我正在尝试设计机器人模拟器的GUI前端(实际上是一个简单的游戏).但是,我不知道将模拟器组件(例如机器人和墙壁)传递给显示器的最佳方法.我想要隐藏组件的非显示方向信息(例如机器人质量),但仍然能够识别每个组件的打印,即当我绘制组件时,我想以不同的方式绘制机器人我做墙壁(也许机器人会有一个名牌或其他东西).
这张照片有望解释设计:

也许有一种有用的设计模式,我还没有遇到过......
我正在尝试使用JX-RS创建Java EE应用程序.我使用以下配置工作:
@ApplicationPath("rs")
public class MyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<>();
// register root resource
classes.add(ProbeREST.class);
return classes;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我更喜欢使用web.xml进行配置.我认为与简单的xml配置相比,上面的内容非常难看,如下所示:
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rs/*</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试部署应用程序时,收到错误:
Exception while deploying the app [my_app] : There is no web component by the name of javax.ws.rs.core.Application here.
Run Code Online (Sandbox Code Playgroud)
我该如何防止此错误?
我正在尝试创建一个动态菜单:像亚马逊或eBay上的菜单一样浏览类别.我的第一次尝试如下所示:
支持bean:
@ManagedBean
@ViewScoped
public class CategoryBackBean implements ActionListener {
private MenuModel model;
private Category category;
public CategoryBackBean() throws IOException {
category = Category.createRootCategory();
createModel();
}
private void createModel() throws IOException {
MenuModel tempModel = new DefaultMenuModel();
for(Category c : category.getChildCategories()) {
MenuItem childItem = new MenuItem();
childItem.setValue(c.getName());
childItem.addActionListener(this);
tempModel.addMenuItem(childItem);
}
this.model = tempModel;
}
public MenuModel getModel() {
return model;
}
@Override
public void processAction(ActionEvent event) throws AbortProcessingException {
try {
MenuItem item = (MenuItem) event.getSource();
String categoryName = …Run Code Online (Sandbox Code Playgroud) 在从 4.5 版升级到 Hibernate Search 5 之前,我们的系统将所有文档 ID 索引为数字字段:
@Entity
public class Staff {
@Id
@NumericField
protected Long id;
// other fields
}
Run Code Online (Sandbox Code Playgroud)
这允许我们使用数字范围查询。在 Hibernate 5 中,所有文档 ID 都被索引为字符串,上面的注释会导致异常。如果没有注释,所有数字范围查询都无法正确搜索 ID 字段。
切换到 TermRangeQuery 而不是 NumericRangeQuery 会很乏味,我希望避免这种情况。
有没有办法继续将 ID 视为数值?
有一张关闭的票证表明Ebean 4.4.1及以后版本支持Java 8的时间类,例如OffsetDateTime.但是,我找不到任何显示使用这些类的Ebean文档.
对于如下AppUser所示的类,是否完全支持使用OffsetDateTime而不是java.sql.Timestamp?
@Entity
public class AppUser extends Model {
@Id
private Long id;
private String username;
private OffsetDateTime lastSeen;
// Constructor, getters and setters
}
Run Code Online (Sandbox Code Playgroud) 我试图运行以下代码:
public BigDecimal valuate(String searchTerms, String categoryPath) {
Query query = em.createNativeQuery("SELECT SUM(maxBidAmount) / COUNT(maxBidAmount) FROM Item WHERE MATCH(title) AGAINST(':searchTerms') AND categoryPath=':categoryPath'", Double.class);
query.setParameter("searchTerms", searchTerms);
query.setParameter("categoryPath", categoryPath);
double value = (double) query.getSingleResult();
return new BigDecimal(value);
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我得到以下异常:
Exception Description: Missing descriptor for [class java.lang.Double].
Run Code Online (Sandbox Code Playgroud)
当我删除时Double.class,我得到一个不同的例外.
所以,我只是想知道在JPQL中使用COUNT和SUM的正确方法.
问题:我将EL表达式传递给复合组件,但EL表达式是从复合组件内部而不是之前进行评估的.将EL表达式求值为字符串的意图发送到复合组件.
我有一个复合组件,MenuTable:
<cc:interface>
<cc:attribute name="model" type="nz.co.tradeintel.web.MenuTable"/>
<cc.attribute name="updateId" />
</cc:interface>
<cc:implementation>
<h:panelGroup id="menuTable">
<table>
<ui:repeat id="repeat1" value="#{cc.attrs.model.rows}" var="row">
<tr>
<ui:repeat id="repeat2" value="#{row.contents}" var="entry">
<td>
<p:commandLink action="#{cc.attrs.model.setSelected(entry)}" update="#{cc.attrs.updateId}" value="#{entry.toString()}"/>
</td>
</ui:repeat>
</tr>
</ui:repeat>
</table>
</h:panelGroup>
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)
目的是我传递一个绝对组件ID作为这样的属性updateId:
<p:PanelGroup id="updatingPanel">
<!-- Lots of components.-->
</p:PanelGroup>
<custom:MenuTable updateId="#{component.clientId}:updatingPanel" model="#{menuBackBean.menuTable}" />
Run Code Online (Sandbox Code Playgroud)
问题是,updateId从<p:commandLink />复合组件内的范围评估的EL表达式,我得到以下错误:
javax.faces.FacesException: Cannot find component with identifier ":j_idt37:j_idt39:updatingPanel:j_idt61:repeat1:0:repeat2:0:j_idt65:updatingPanel" referenced from "j_idt37:j_idt39:updatingPanel:j_idt61:repeat1:0:repeat2:0:j_idt65".
Run Code Online (Sandbox Code Playgroud)
注:JSF认为我试图更新组件与和ID的updatingPanel是内部的复合材料部件.
为什么不从外部范围评估EL表达式:<custom:MenuTable/>?
有一些相关的答案,但我不理解它们,比如这个.
使用Mojarra 2.1.15
我正在尝试修改PrimeFaces 菜单(不是 MenuBar),使其水平显示。
我正在尝试应用这样的样式:
<h:form>
<p:menu styleClass="horizontalMenu">
<p:menuitem value="Home" url="./home.xhtml"/>
<p:menuitem value="Contact Us" url="./contactUs.xhtml"/>
<p:menuitem value="Shop" url="./shop.xhtml"/>
</p:menu>
</h:form>
Run Code Online (Sandbox Code Playgroud)
在单独的 CSS 文件中,我有以下内容:
.horizontalMenu li {
display:inline;
float:none;
}
Run Code Online (Sandbox Code Playgroud)
但是,我的样式总是被 PrimeFaces 样式覆盖(例如 .ui-menuitem)。
我希望有一个非全局的解决方案,因为我可能也需要垂直菜单,所以这排除了编辑主题的 CSS 文件。