<f:viewParam> not being set during <h:form> submit - jsf

I would like to create a form to simply modify the fields of some project entity.
To do so I created a request scoped bean and a view that uses together with a converter to tell the bean which entity is being edited.
Bean
#Named
#RequestScoped
public class Bean {
private Project selectedProject;
public void setSelectedProject(Project project) {
selectedProject= project;
}
public Project getSelectedProject() {
return selectedProject;
}
public String save() {
// Persist selectedProject...
return null;
}
}
View
<ui:composition template="/templates/layout.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<ui:define name="metadata">
<f:metadata>
<f:viewParam id="projectParam" name="project"
value="#{bean.selectedProject}" converter="#{projectConverter}" />
</f:metadata>
</ui:define>
<ui:define name="content">
<h:form id="projectForm">
<p:panel header="Project details">
<h:panelGrid columns="2">
<p:outputLabel for="title" value="Title" />
<h:inputText id="title" value="#{bean.selectedProject.title}" />
<p:outputLabel for="desc" value="Description" />
<h:inputTextarea id="desc" value="#{bean.selectedProject.description}" />
</h:panelGrid>
<p:commandButton id="submitButton" type="submit"
value="Save" action="#{bean.save}">
<f:param name="project" value="#{bean.selectedProject.id}" />
</p:commandButton>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
Loading the view initially works fine, the chosen project is loaded and the form fields are filled with the project's properties. However when saving the form I receive the following stack trace:
11:00:58,837 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http--0.0.0.0-8080-3) /user/project.xhtml #42,70 value="#{bean.selectedProject.title}": Target Unreachable, 'selectedProject' returned null: javax.el.PropertyNotFoundException: /user/project.xhtml #42,70 value="#{bean.selectedProject.title}": Target Unreachable, 'selectedProject' returned null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.validate(UIInput.java:960) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.processValidators(UIInput.java:698) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.primefaces.component.panel.Panel.processValidators(Panel.java:297) [primefaces-3.5.jar:]
at javax.faces.component.UIForm.processValidators(UIForm.java:253) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.primefaces.component.layout.Layout.processValidators(Layout.java:246) [primefaces-3.5.jar:]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:680) [classes.jar:1.6.0_51]
While debugging the problem I found out that the converter is indeed called, but the returned project is not set on the bean before the above lifecycle occurs. If I return a dummy project in the bean, everything works fine, the selected project is eventually set I can be persisted with the updated values.
Is this expected behaviour? Can I get this running without returning a dummy project?
I've seen approaches with view scoped beans. Since we're using CDI I'd prefer to stick to javax.enterprise annotations. If you think the rest of the code (template, converter) are of any relevance I'm happy to add them.

It is an expected behaviour. With <f:viewParam /> you're setting the value in the bean during GET request. Value is set, that's why your page is rendered properly, however your bean is #RequestScoped, so its state is lost from one request to the other one. When you perform the POST request with your p:commandButton, its value is actually null. To solve it, you should use #ViewScoped bean.

Related

java.lang.ClassCastException: org.primefaces.component.column.Column cannot be cast to org.primefaces.component.row.Row

I am trying to make a data search on a table. I have tried to follow the example in the showcase primefaces for the DataTable filter. However, strangely when I enter the value that I want to find, the contents of the table will immediately empty. For example I want to find the username 'A', then when I type 'A' the contents of the table will disappear.
Here is my table:
<h:form id="dataTable">
<p:dataTable var="users" rows="10" value="#{listUserAccountBean.users}"
style="width: 100%; float: left; margin-top:10px;" paginator="true"
pageLinks="10" rowsPerPageTemplate="5,10,15"
widgetVar="widgetWorkOrder" rowIndexVar="rowIndex"
paginatorPosition="bottom" emptyMessage="No record found"
styleClass="no-dtbl-header" id="listDataUser" filteredValue="#{listUserAccountBean.filteredUsers}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="PF('widgetWorkOrder').filter()" placeholder="Enter keyword"/>
</p:outputPanel>
</f:facet>
<p:columnGroup type="header">
<p:column headerText="Username" />
<p:column headerText="Password" />
<p:column headerText="Action" colspan="2"/>
</p:columnGroup>
<p:column filterBy="#{users.username}" footerText="test1" filterMatchMode="test1">
<h:outputText value="#{users.username}" />
</p:column>
<p:column filterBy="#{users.password}" footerText="test2" filterMatchMode="test2">
<h:outputText value="#{users.password}" />
</p:column>
<p:column style="text-align: center">
<p:commandLink action="#{listUserAccountBean.goToEditUserAccount(users)}">
<p:graphicImage name="edit.png" library="images" width="25px"
height="25px" />
</p:commandLink>
</p:column>
<p:column style="text-align: center">
<p:commandLink actionListener="#{listUserAccountBean.prepareDelete(users)}"
oncomplete="PF('dlg-delete').show();">
<p:graphicImage name="delete-admin.png" library="images"
width="25px" height="25px" />
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
Here is my log cat:
14:37:38,073 INFO [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost-127.0.0.1-8081-2) java.lang.ClassCastException: org.primefaces.component.column.Column cannot be cast to org.primefaces.component.row.Row: java.lang.ClassCastException: org.primefaces.component.column.Column cannot be cast to org.primefaces.component.row.Row
at org.primefaces.component.datatable.feature.FilterFeature.populateFilterMetaDataInColumnGroup(FilterFeature.java:283) [primefaces-5.3.jar:5.3]
at org.primefaces.component.datatable.feature.FilterFeature.populateFilterMetaData(FilterFeature.java:257) [primefaces-5.3.jar:5.3]
at org.primefaces.component.datatable.feature.FilterFeature.decode(FilterFeature.java:90) [primefaces-5.3.jar:5.3]
at org.primefaces.component.datatable.DataTable.processValidators(DataTable.java:716) [primefaces-5.3.jar:5.3]
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:508) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.primefaces.component.api.UIData.visitTree(UIData.java:822) [primefaces-5.3.jar:5.3]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIForm.visitTree(UIForm.java:371) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:376) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:252) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60) [primefaces-5.3.jar:5.3]
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1170) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.logging.log4j.web.Log4jServletFilter.doFilter(Log4jServletFilter.java:67) [log4j-web-2.0.2.jar:2.0.2]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]
14:37:38,020 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost-127.0.0.1-8081-2) java.lang.NullPointerException
Did I miss something?
Add a p:row as child of p:columnGroup wrapping your p:column.
<p:columnGroup type="header">
<p:row>
<p:column headerText="Username" />
<p:column headerText="Password" />
<p:column headerText="Action" colspan="2"/>
</p:row>
</p:columnGroup>
It seems PrimeFaces code searches the first child of columnGroup and tries to cast it to column.

p:commandButton inside Orderlist not working

I've got a question regarding Primefaces orderList.
I have an orderList which looks like this:
<p:orderList id="technikersTable"
value="#{systemlandschaftRessourceHandler.entity.technikers}"
var="_techniker"
itemValue="#{_techniker}"
converter="#{entityConverter}"
controlsLocation="none">
<f:facet name="caption">Techniker</f:facet>
<p:column>
<p:commandButton styleClass="colButton"
icon="ui-icon-trash"
action="#{systemlandschaftRessourceHandler.removeTechniker(_techniker)}"
update=":systemLandschaftTabView:sysObjektDetailPanelForm:technikersTable"/>
</p:column>
<p:column style="width:75%;">
<p:outputLabel value="#{_techniker.verantwortlich.displayName}" />
</p:column>
</p:orderList>
My problem is, that the commandButton in the first column throws a null pointer exception.
The request never reaches my bean.
Is it possible that the commandButton is not working inside the orderList?
I have done the same thing with dataTables a lot of time successfully.
StackTrace:
ERROR 2013-10-15 14:37:55,009 [MmnetExceptionHandler] Fehler auf der Seite: /views/protected/systemlandschaft/systemlandschaftHome.xhtml, isAjaxRequest=true
ERROR 2013-10-15 14:37:55,010 [MmnetExceptionHandler] [SCUE070] Allgemeiner Anwendungsfehler! : java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.apache.el.util.ReflectionUtil.isAssignableFrom(ReflectionUtil.java:319)
at org.apache.el.util.ReflectionUtil.getMethod(ReflectionUtil.java:185)
at org.apache.el.parser.AstValue.invoke(AstValue.java:257)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at org.apache.myfaces.extensions.cdi.jsf.impl.security.SecurityViolationAwareActionListener.processAction(SecurityViolationAwareActionListener.java:56)
at org.apache.myfaces.extensions.cdi.jsf.impl.config.view.ViewControllerActionListener.processAction(ViewControllerActionListener.java:68)
at org.apache.myfaces.extensions.cdi.jsf.impl.listener.action.CodiActionListener.processAction(CodiActionListener.java:58)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIData.broadcast(UIData.java:1093)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at org.apache.myfaces.extensions.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.execute(CodiLifecycleWrapper.java:95)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:118)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at de.company.mmnet.sessioninfo.HttpSessionUserFilter.doFilter(HttpSessionUserFilter.java:42)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:165)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
at java.lang.Thread.run(Thread.java:722)
DEBUG 2013-10-15 14:37:55,094 [EntityManagerProducer] EntityManager geschlossen.
You can use a commandbutton inside an orderList. Your problem is that you are using the #{_techniker} var as a parameter. The action property is evaluating the EL expression on serverside when you click the button, and this is causing the nullpointer.
It does indeed work in a dataTable, but the datatable component is designed differently.
I would consider using a different component, but if you really need to use the orderlist, you could use the p:remoteCommand for sending the id of the techniker to the backing bean.
Primefaces RemoteCommand
Expanding LStrike comment, here is the relevant content from https://forum.primefaces.org/viewtopic.php?f=3&t=34424
Bean:
#ManagedBean
#RequestScoped
public class TechnikersBean {
public List<String> getPersons() {
List<String> result = new ArrayList<String>();
result.add("Person1");
result.add("person2");
return result;
}
public void setPersons(List<String> persons) {
}
public void removeTechniker(ActionEvent event) {
Map<String, String> parameterMap = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap();
String name = parameterMap.get("name");
System.out.println(name);
}
}
xhtml:
<h:form id="form">
<p:remoteCommand name="removeTechniker" actionListener="#{technikersBean.removeTechniker}"
out="technikersTable" />
<p:orderList id="technikersTable"
value="#{technikersBean.persons}"
var="_techniker"
itemValue="#{_techniker}"
controlsLocation="none">
<f:facet name="caption">Techniker</f:facet>
<p:column>
<p:commandButton styleClass="colButton"
icon="ui-icon-trash"
type="button" onclick="removeTechniker([{name:'name', value:'#{_techniker}'}]);">
</p:commandButton>
</p:column>
<p:column style="width:75%;">
<p:outputLabel value="#{_techniker}"/>
</p:column>
</p:orderList>
</h:form>
Basically, a remoteComand is called by a client side callback to send the required information to the bean function.

Target unreachable CDI

I try to connect my web application with CDI but it don't want to work... There is an beans.xml file in WEB-INF. When I try to access fields from the CDI-Bean I get an javax.el.PropertyNotFoundException
index.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Simple JSF Facelets page</title>
</h:head>
<h:body>
<h:form >
<p:panelGrid columns="2">
<h:outputLabel for="username" value="Username: "/>
<p:inputText id="username" value="#{credentials.username}" />
</p:panelGrid>
<p:commandButton value="Login" action="#{credentials.login}" />
</h:form>
</h:body>
</html>
Credentials.java
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
#Named
#RequestScoped
public class Credentials{
private String username;
private String password;
#Inject
AuthController authController;
public String login(){
authController.authenticate(username);
return "start";
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
AuthController.java
import addressbook.baselibs.enterprise.stereotype.Current;
import addressbook.user.entity.User;
import addressbook.user.repository.UserRepository;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
#Named
#RequestScoped
public class AuthController implements Serializable{
#Inject
private Authentication authentication;
#Inject
private UserRepository userRepository;
#Inject
private FacesContext facesContext;
#Inject
private Conversation conversation;
#Produces
#Named
#Current
public User getCurrentUser() {
return authentication.getCurrentUser();
}
public void authenticate(String username) {
if(isLogged()) {
throw new IllegalStateException("User is logged and tries to authenticate again");
}
User user = userRepository.getForUserName(username);
if(user == null) {
// User not Found
}
authentication.setCurrentUser(user);
conversation.begin();
}
public void logout() {
authentication.setCurrentUser(null);
conversation.end();
}
public boolean isLogged() {
return authentication.getCurrentUser() != null;
}
}
Stacktrace
00:58:49,975 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (http--127.0.0.1-8080-1) /index.xhtml #15,86 value="#{credentials.username}": Target Unreachable, identifier 'credentials' resolved to null: javax.el.PropertyNotFoundException: /index.xhtml #15,86 value="#{credentials.username}": Target Unreachable, identifier 'credentials' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.primefaces.renderkit.InputRenderer.getConverter(InputRenderer.java:154) [primefaces-3.1.1.jar:]
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:167) [primefaces-3.1.1.jar:]
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1030) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.validate(UIInput.java:960) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.executeValidate(UIInput.java:1233) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIInput.processValidators(UIInput.java:698) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIForm.processValidators(UIForm.java:253) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.primefaces.component.layout.Layout.processValidators(Layout.java:245) [primefaces-3.1.1.jar:]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1214) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1172) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_21]
Looks like you are injecting "conversation" scoped component in AuthController (private Conversation conversation)... Conversation scoped component is processed by Seam if
#Inject is used to perform injection after the RESTORE_VIEW phase..So during the "RESTORE_VIEW" phase this CONVERSATION scoped component will not be able to be instantiated and throws up
this error...Can you try to use
Component.getInstance() instead of
#inject for this conversation component and see if it helped resolved the issue?

JSF 2.1 + CDI handling ActionEvent throws ViewExpiredException

I'am trying to run simple example of my web app. I'am using JSF + CDI bean.
My facelet:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<h:html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:outputLabel value="#{testBEan.tekst}" />
<h:form>
<h:commandButton actionListener="#{testBEan.dodajCos}" value="guzik" />
</h:form>
</h:body>
</h:html>
My CDI BEAN:
package pl.com.hrms.pages;
import javax.faces.bean.ApplicationScoped;
import javax.faces.event.ActionEvent;
import javax.inject.Named;
#Named
#ApplicationScoped
public class TestBEan
{
String tekst = "1";
public String getTekst()
{
tekst = tekst+"2";
return tekst;
}
public void setTekst(String tekst)
{
this.tekst = tekst;
}
public void dodajCos(ActionEvent e)
{
tekst = tekst+"p";
}
}
When i run it web browser show the label with value "12" and button. If i press the button threse is an Exception throwing
19:05:05,903 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/H&RMSWeb].[Faces Servlet]] (http-0.0.0.0-0.0.0.0-8080-1) Servlet.service() for servlet Faces Servlet threw exception: javax.faces.application.ViewExpiredException: viewId:/pages/test.jsf - View /pages/test.jsf could not be restored.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:205) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_03]
If i use #ManagedBean instead of of #Named it works fine (i mean pressing the button causes adding "p" to the label).
I have beans.xml file in a WEB-INF.
Does anyone have idea what am i doing wrong?
Please do not mix the JSF Scope and CDI Scope.
The JSF
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
#ApplicationScoped
#ManagedBean
public class MyBean {
}
The CDI
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
#ApplicationScoped
#Named
public class MyBean {
}
I hope this may help.

PrimeFaces/JSF component ID not found from within p:datatable

I'm just starting with PrimeFaces 3.3.1 coming off RichFaces 3 and 4.
I have a datatable with the structure:
<f:facet name="header">
<h:outputText value="Employees" />
</f:facet>
<p:column sortBy="#{emp.lastName}">
<f:facet name="header">
<h:outputText value="Last Name" />
</f:facet>
<h:outputText value="#{emp.lastName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="First Name" />
</f:facet>
<h:outputText value="#{emp.firstName}" />
</p:column>
...
<p:column>
<p:commandButton icon="ui-icon ui-icon-trash"
value="Remove"
process="#this"
update="employee-remove-dialog"
oncomplete="employeeRemoveDialog.show();">
<f:setPropertyActionListener target="#{employeeManager.currentEmployee}" value="#{emp}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Remove Employee"
modal="true"
appendToBody="true"
widgetVar="employeeRemoveDialog"
id="employee-remove-dialog">
<h:outputText value="Remove employee #{employeeManager.currentEmployee.fullName}?" />
<f:facet name="footer">
<p:commandButton icon="ui-icon ui-icon-check"
value="OK"
action="#{employeeManager.deleteEmployee}"
process="#this"
update="employee-list"
oncomplete="employeeRemoveDialog.hide();" />
<p:commandButton icon="ui-icon ui-icon-close"
value="Cancel"
onclick="employeeRemoveDialog.hide();"
ajax="false"
immediate="true" />
</f:facet>
</p:dialog>
</h:form>
However PrimeFaces throws an exception:
09:36:08,961 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost-127.0.0.1-8080-1) Error Rendering View[/employeeList.xhtml]: javax.faces.FacesException: Cannot find component with identifier "employee-remove-dialog" referenced from "j_idt30:employee-list:0:j_idt41".
at org.primefaces.util.ComponentUtils.findClientIds(ComponentUtils.java:251) [primefaces-3.3.1.jar:]
at org.primefaces.util.AjaxRequestBuilder.addIds(AjaxRequestBuilder.java:102) [primefaces-3.3.1.jar:]
at org.primefaces.util.AjaxRequestBuilder.update(AjaxRequestBuilder.java:90) [primefaces-3.3.1.jar:]
at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:195) [primefaces-3.3.1.jar:]
at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeMarkup(CommandButtonRenderer.java:74) [primefaces-3.3.1.jar:]
at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeEnd(CommandButtonRenderer.java:49) [primefaces-3.3.1.jar:]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularCell(DataTableRenderer.java:780) [primefaces-3.3.1.jar:]
at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:741) [primefaces-3.3.1.jar:]
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:645) [primefaces-3.3.1.jar:]
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:248) [primefaces-3.3.1.jar:]
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:220) [primefaces-3.3.1.jar:]
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:107) [primefaces-3.3.1.jar:]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55) [primefaces-3.3.1.jar:]
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43) [primefaces-3.3.1.jar:]
at org.primefaces.component.layout.LayoutUnitRenderer.encodeEnd(LayoutUnitRenderer.java:51) [primefaces-3.3.1.jar:]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_04]
The ID cannot be found. Hmm.... I basically copied the structure from RichFaces. There the row button to delete or edit the row doesn't need the :employee-form:... prefixing. I wonder why.
When giving the form an ID and prefixing the PF component references with the ':' syntax the code runs as expected:
<h:form id="employee-form">
<p:dataTable ...>
...
<p:column>
<h:panelGrid ...>
<p:commandButton ...
update=":employee-form:employee-remove-dialog"
...>
...
</p:commandButton>
</h:panelGrid>
</p:column>
</p:dataTable>
<p:dialog ...
id="employee-remove-dialog">
</p:dialog>
</h:form>
Q:
Why does a p:datatable need to prefix the root JSF IDs? Maybe it's my code, but the example posted seems minimal to me. In any case, using this will result in possibly long IDs all over the application.
What am I doing wrong?
PS: I'm on JBoss AS 7.1.1.Final, Mojarra 2.1.7, PF 3.3.1
PrimeFaces uses the standard JSF algorithm as provided by UIComponent#findComponent() to find components by a given client ID. The algorithm is in detail described in the aforelinked javadoc. Here's an extract of relevance:
A search expression consists of either an identifier (which is matched exactly against the id property of a UIComponent, or a series of such identifiers linked by the UINamingContainer#getSeparatorChar character value. The search algorithm should operates as follows, though alternate alogrithms may be used as long as the end result is the same:
Identify the UIComponent that will be the base for searching, by stopping as soon as one of the following conditions is met:
If the search expression begins with the the separator character (called an "absolute" search expression), the base will be the root UIComponent of the component tree. The leading separator character will be stripped off, and the remainder of the search expression will be treated as a "relative" search expression as described below.
Otherwise, if this UIComponent is a NamingContainer it will serve as the basis.
Otherwise, search up the parents of this component. If a NamingContainer is encountered, it will be the base.
Otherwise (if no NamingContainer is encountered) the root UIComponent will be the base.
The search expression (possibly modified in the previous step) is now a "relative" search expression that will be used to locate the component (if any) that has an id that matches, within the scope of the base component. The match is performed as follows:
If the search expression is a simple identifier, this value is compared to the id property, and then recursively through the facets and children of the base UIComponent (except that if a descendant NamingContainer is found, its own facets and children are not searched).
If the search expression includes more than one identifier separated by the separator character, the first identifier is used to locate a NamingContainer by the rules in the previous bullet point. Then, the findComponent() method of this NamingContainer will be called, passing the remainder of the search expression.
RichFaces uses the same algorithm "with some additional exceptions".
"reRender" uses UIComponent.findComponent() algorithm (with some additional exceptions) to find the component in the component tree.
Those additional exceptions are nowhere in detail described, but it's well known that relative component IDs (i.e. those not starting with :) are not only searched in the context of the closest parent NamingContainer, but also in all other NamingContainer components in the same view (which is a relatively expensive job by the way).

Resources