在 Facelet 上,我尝试使用<pe:remoteCommand>
更新 backingbean 值:
<pe:remoteCommand name="saveMapArea" process="@this" actionListener="#{defineMapArea.createMapArea}">
<pe:assignableParam name="areaString" assignTo="#{defineMapArea.tagMapArea.mapArea}"/>
<pe:assignableParam name="areaName" assignTo="#{defineMapArea.tagMapArea.name}" />
<pe:assignableParam name="castId" assingTo="#{defineMapArea.tagMapArea.castId}" />
</pe:remoteCommand>
castId
当用户单击提交按钮时,jQuery 从下拉列表中检索值,下拉列表的代码是:
<h:selectOneMenu id="area_assign_device">
<f:selectItem itemLabel="Select Icast" itemValue="" />
<f:selectItems value="#{defineMapArea.castList}" var="cast" itemLabel="#{cast.name}" itemValue="#{cast.castId}"/>
</h:selectOneMenu>
提交按钮的代码是:
<p:commandButton value="Submit" type="button" onclick="CreateArea.saveArea()"/>
调用 remotecommand 'saveMapArea' 的代码是:
saveArea : function() {
if(CreateArea.validate()) {
// ...some other code to init map area...
var name=jQuery('#area_name_text').val();
var castId=jQuery('#area_assign_device').val();
saveMapArea(mapArea, name, castId);
CreateArea.points = [];
}
}
我的支持豆是:
@ManagedBean
@RequestScoped
public class DefineMapArea extends BaseJsfBean {
private static final long serialVersionUID = 1L;
private static Log log = LogFactory.getLog(DefineMapArea.class);
private TagMapArea tagMapArea;
private List<TagMapArea> areaList;
private String areaListJson;
@ManagedProperty(value="#{tagCustomService}")
private ITagCustomService tagCustomService;
@Override
protected void init() throws Exception {
// ..some initializations...
}
public void createMapArea() {
log.info("Area Persisting : " + tagMapArea.getMapArea());
tagMapArea.setTagMapImageId(2);
tagMapArea.setMapAreaType("test");
tagMapArea.setDescription("test");
}
// ....all the getters and setters....
}
TagMapArea
是 JPA 实体,包括castId
字段的部分是:
@Column(name = "cast_id", nullable = false)
protected Integer castId;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="cast_id", nullable=false, insertable=false, updatable=false)
protected TagCast cast;
问题是当我点击提交按钮时,它会抛出NullPointerException
这样的:
java.lang.NullPointerException
at org.primefaces.extensions.component.remotecommand.RemoteCommandRenderer.decode(RemoteCommandRenderer.java:82)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1377)
at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:731)
at org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:214)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:932)
我很确定这是由castId
远程命令中的字段引起的,因为如果我删除该字段,它就可以正常工作。我很困惑为什么从下拉列表中检索到的选定值没有发送到远程命令。有谁知道问题出在哪里?