这是我的HTML文件
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition>
<h:form id="UserTagsForm" >
<h:panelGrid id="pgrid" columns="1" cellpadding="5" cellspacing="5" style="margin: 0 auto;margin-top: 25px" >
<p:outputLabel value="Select ChipId of pod" for="chipIdList" />
<p:selectOneMenu id="chipIdList" value="#{usertagsController.selected.chipId}" required="true" requiredMessage="Chip Id required" converter="podConverter" >
<f:selectItem itemLabel="#{messages.SelectOneMessage} " />
<f:selectItems value="#{podController.items}"
var="chipidItems"
itemValue="#{chipidItems}"
itemLabel="#{chipidItems.chipId.toString()}"/>
</p:selectOneMenu>
<p:outputLabel value="Select Event Type" for="eventTypeList" />
<p:selectOneMenu id="eventTypeList" value="#{usertagsController.selected.eventType}" required="true" requiredMessage="Event Type List required" converter="usertagseventnamesConverter" >
<f:selectItem itemLabel="#{messages.SelectOneMessage} " />
<f:selectItems value="#{usertagseventnamesController.items}"
var="eventItems"
itemValue="#{eventItems}"
itemLabel="#{eventItems.eventDesc.toString()}"/>
</p:selectOneMenu>
<p:outputLabel for="datetime" value="Choose Datetime:" />
<p:calendar id="datetime" value="#{usertagsController.selected.dateTime}" pattern="MM/dd/yyyy HH:mm:ss" required="true" requiredMessage="Date time required"/>
<f:facet name="footer">
<p:commandButton value="Save" id="saveBtn" actionListener="#{usertagsController.saveNew}" icon="ui-icon-disk" />
</f:facet>
<p:blockUI block="pgrid" trigger="saveBtn" />
</h:panelGrid>
<ui:include src="/confirmation.xhtml"/>
</h:form>
</ui:composition>
</html>
2.这是我的BeanController
。
@ManagedBean
@ViewScoped
public class UsertagsController extends AbstractController<UserTags> implements java.io.Serializable{
private static final long serialVersionUID = -4377337774610224471L;
@ManagedProperty("#{podController}")
private PodController podController ;
@ManagedProperty("#{usertagseventnamesController}")
private UsertagseventnamesController usertagseventnamesController;
public UsertagsController() {
super(UserTags.class);
columnNames();
columnList();
}
public PodController getPodController() {
return podController;
}
public void setPodController(PodController podController) {
this.podController = podController;
}
public UsertagseventnamesController getUsertagseventnamesController() {
return usertagseventnamesController;
}
public void setUsertagseventnamesController(UsertagseventnamesController usertagseventnamesController) {
this.usertagseventnamesController = usertagseventnamesController;
}
@Override
public void saveNew(ActionEvent event) {
super.saveNew(event);
}
@Override
public void resetParents() {
podController.setSelected(null);
usertagseventnamesController.setSelected(null);
}
}
这是我扩展AbstractController
的课程:
public class AbstractController<T> {
protected IGenericDAO<T> dao;
protected IColumnSettings columnsDAO = new ColumnSettingsDAOImpl();
private T selected;
private List<T> filtered;
private Class<T> itemClass;
private Collection<T> items;
private enum PersistAction {
CREATE,
DELETE,
UPDATE
}
public AbstractController(Class<T> itemClass) {
//super(itemClass);
dao = new GenericDAOImpl<T>(itemClass);
this.itemClass = itemClass;
listVisible = new ArrayList<Boolean>();
listWidth = new ArrayList<>();
//columnList();
}
public T getSelected() {
return selected;
}
public void setSelected(T selected) {
this.selected = selected;
}
public List<T> getFiltered() {
return filtered;
}
public void setFiltered(List<T> filtered) {
this.filtered = filtered;
}
public Class<T> getItemClass() {
return itemClass;
}
public void save(ActionEvent event) {
String msg = ResourceBundle.getBundle("/messages").getString(itemClass.getSimpleName() + "Updated");
persist(PersistAction.UPDATE, msg);
if (!isValidationFailed()) {
selected = null;
}
}
public void saveNew(ActionEvent event) {
String msg = ResourceBundle.getBundle("/messages").getString(itemClass.getSimpleName() + "Created");
persist(PersistAction.CREATE, msg);
if (!isValidationFailed()) {
selected = null;
}
}
public void delete(ActionEvent event) {
String msg = ResourceBundle.getBundle("/messages").getString(itemClass.getSimpleName() + "Deleted");
persist(PersistAction.DELETE, msg);
if (!isValidationFailed()) {
selected = null; // Remove selection
}
}
}
这是例外结果:
javax.el.PropertyNotFoundException: /patient_blankPage.xhtml @16,173 value="#{usertagsController.selected.chipId}": Target Unreachable, 'null' returned null
at javax.faces.component.UIInput.updateModel(UIInput.java:866)
at javax.faces.component.UIInput.processUpdates(UIInput.java:749)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIForm.processUpdates(UIForm.java:281)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIComponentBase.processUpdates(UIComponentBase.java:1291)
at javax.faces.component.UIViewRoot.processUpdates(UIViewRoot.java:1254)
at com.sun.faces.lifecycle.UpdateModelValuesPhase.execute(UpdateModelValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at com.dwadmin.filters.AuthorizationFilter.doFilter(AuthorizationFilter.java:48)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:591)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:571)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.el.PropertyNotFoundException: /patient_blankPage.xhtml @16,173 value="#{usertagsController.selected.chipId}": Target Unreachable, 'null' returned null
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:133)
at javax.faces.component.UIInput.updateModel(UIInput.java:832)
... 44 more
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, 'null' returned null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:192)
at com.sun.el.parser.AstValue.setValue(AstValue.java:226)
at com.sun.el.ValueExpressionImpl.setValue(ValueExpressionImpl.java:294)
at org.jboss.weld.el.WeldValueExpression.setValue(WeldValueExpression.java:64)
at com.sun.faces.facelets.el.TagValueExpression.setValue(TagValueExpression.java:131)
... 45 more
答案 0 :(得分:0)
这是因为“selected”字段为null。它需要在构造UsertagsController对象期间初始化(理想位置将在构造函数中),以便更新模型阶段更新值。