In my JSF/PrimeFaces mini web project I want to use a drop down list to select Enum items, then add them to a database when I fill in the 'create' form.
I used Netbeans to create an Entity class from a database, and then used to the wizard 'JSF pages from Entity classes', with PrimeFaces as the template. This creates Create / Edit / List / View xhtml pages automatically.
At the moment I've got:
Enum class:
public enum InterestsEnum {
FOOTBALL,
SKIING,
CYCLING,
MUSIC;
}
Entity class:
#Entity
public class Person implements Serializable {
#Column(name="ID")
#Id
#NotNull
#GeneratedValue(strategy = GenerationType.AUTO)
private Long personId;
#Column(name="FIRSTNAME")
#Basic(optional=false)
#NotNull
#Size(min=1,max=45)
private String firstName;
#Column(name="SURNAME")
#Basic(optional=false)
#NotNull
#Size(min=1,max=45)
private String surname;
#ElementCollection(fetch = FetchType.EAGER, targetClass = InterestsEnum.class)
#JoinTable(name = "Person_INTERESTS", joinColumns = #JoinColumn(name = "PERSON_ID"))
#Column(name = "INTERESTS", nullable = false)
#Enumerated(EnumType.STRING)
Collection<InterestsEnum> interests;
//Getters and Setters:
Managed Bean:
#ManagedBean
#ApplicationScoped
public class Data {
public InterestsEnum[] getInterests() {
return InterestsEnum.values();
}
}
PrimeFaces Create page extract:
<p:selectOneMenu value="#{person.interests}" >
<f:selectItems value="#{InterestsEnum}" />
</p:selectOneMenu>
PrimeFaces List page extract:
<p:column>
<f:facet name="header">
<h:outputText value="#{bundle.ListPersonTitle_interests}"/>
</f:facet>
<h:outputText value="#{item.interests}"/>
</p:column>
When I run the project there are no errors until I open 'List', when the following happens:
Severe: Error Rendering View[/person/List.xhtml]
javax.faces.FacesException: Cannot find component with expression "interests" referenced from "PersonCreateForm:j_idt34".
at org.primefaces.expression.SearchExpressionFacade.resolveComponentInternal(SearchExpressionFacade.java:422)
at org.primefaces.expression.SearchExpressionFacade.resolveComponent(SearchExpressionFacade.java:266)
at org.primefaces.expression.SearchExpressionFacade.resolveComponent(SearchExpressionFacade.java:228)
at org.primefaces.component.outputlabel.OutputLabelRenderer.encodeEnd(OutputLabelRenderer.java:47)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeDynamicBody(PanelGridRenderer.java:89)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeBody(PanelGridRenderer.java:60)
at org.primefaces.component.panelgrid.PanelGridRenderer.encodeEnd(PanelGridRenderer.java:49)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:114)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:582)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at javax.faces.component.UIForm.visitTree(UIForm.java:381)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1700)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:322)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:432)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
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:745)
If I submit the 'create' form I get the following error:
Severe: javax.faces.component.UpdateModelException: javax.el.PropertyNotFoundException: /person/Create.xhtml #24,71 value="#{Person.interests}": Target Unreachable, identifier 'Person' resolved to null
There is no drop down list to select Enum choices from (see screenshot). Also 'List' shows all the Enum members, not just one.
After simplifying my project and using one table instead of two and updating my Entity class to:
#Column(name = "INTERESTS")
#Enumerated(EnumType.STRING)
private InterestsEnum interests;
I now have a working project which allows a user to choose Enum members when creating or updating entries.
<h:selectOneMenu value="#{personController.selected.interests}" >
<f:selectItems value="#{data.interests}" />
</h:selectOneMenu>
This can be seen below:
Related
I have upgraded PrimeFaces from 5.1 final to 5.2 final (the Community Release). I have a <p:dataTable> which is lazily loaded as follows (a minimal example to reproduce the problem for a pure testing purpose only).
<p:dataTable var="row"
value="#{testManagedBean}"
lazy="true"
editable="true"
rowKey="#{row.fruitId}"
selection="#{testManagedBean.selectedValues}"
rows="50">
<p:column selectionMode="multiple"/>
<p:ajax event="rowEdit" listener="#{testManagedBean.onRowEdit}"/>
<p:column headerText="Id">
<h:outputText value="#{row.fruitId}"/>
</p:column>
<p:column headerText="Fruit Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.fruitName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{row.fruitName}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Price">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.price}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{row.price}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit">
<p:rowEditor/>
</p:column>
</p:dataTable>
The corresponding managed bean :
#Named
#ViewScoped
public class TestManagedBean extends LazyDataModel<Fruit> implements Serializable {
private List<Fruit> selectedValues; // Getter & setter.
private static final long serialVersionUID = 1L;
public TestManagedBean() {}
private List<Fruit> init() {
List<Fruit> fruits = new ArrayList<Fruit>();
Fruit fruit = new Fruit();
fruit.setFruitId(1);
fruit.setFruitName("Mango");
fruit.setPrice(500D);
fruits.add(fruit);
fruit = new Fruit();
fruit.setFruitId(2);
fruit.setFruitName("Guava");
fruit.setPrice(300D);
fruits.add(fruit);
fruit = new Fruit();
fruit.setFruitId(3);
fruit.setFruitName("Apple");
fruit.setPrice(600D);
fruits.add(fruit);
return fruits;
}
#Override
public List<Fruit> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
List<Fruit> fruits = init();
setRowCount(fruits.size());
return fruits;
}
public void onRowEdit(RowEditEvent event) {
System.out.println("id : "+((Fruit)event.getObject()).getFruitId());
}
}
While editing the onRowEdit() method is supposed to be invoked which is bound to,
<p:ajax event="rowEdit" listener="#{testManagedBean.onRowEdit}"/>
When a row is in an edit mode and the update link marked by a tick is clicked, it causes the following exception to be thrown.
Info: java.lang.UnsupportedOperationException: getRowData(String rowKey) must be implemented when basic rowKey algorithm is not used.
java.lang.UnsupportedOperationException: getRowData(String rowKey) must be implemented when basic rowKey algorithm is not used.
at org.primefaces.model.LazyDataModel.getRowData(LazyDataModel.java:95)
at org.primefaces.component.datatable.DataTable.getRowData(DataTable.java:1214)
at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:90)
at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:48)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:62)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:834)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:281)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:573)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:821)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at javax.faces.component.UIForm.visitTree(UIForm.java:380)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:930)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.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:660)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
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:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
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:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
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:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
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:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Warning: java.lang.UnsupportedOperationException: getRowData(String rowKey) must be implemented when basic rowKey algorithm is not used.
javax.faces.FacesException: java.lang.UnsupportedOperationException: getRowData(String rowKey) must be implemented when basic rowKey algorithm is not used.
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:273)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:930)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.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:660)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
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:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
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:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
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:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
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:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.UnsupportedOperationException: getRowData(String rowKey) must be implemented when basic rowKey algorithm is not used.
at org.primefaces.model.LazyDataModel.getRowData(LazyDataModel.java:95)
at org.primefaces.component.datatable.DataTable.getRowData(DataTable.java:1214)
at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:90)
at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:48)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:62)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:834)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:281)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:573)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:821)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at javax.faces.component.UIForm.visitTree(UIForm.java:380)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266)
... 34 more
Severe: java.lang.UnsupportedOperationException: getRowData(String rowKey) must be implemented when basic rowKey algorithm is not used.
at org.primefaces.model.LazyDataModel.getRowData(LazyDataModel.java:95)
at org.primefaces.component.datatable.DataTable.getRowData(DataTable.java:1214)
at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:90)
at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:48)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:62)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:834)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:281)
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:573)
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)
at org.primefaces.component.api.UIData.visitTree(UIData.java:821)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at javax.faces.component.UIForm.visitTree(UIForm.java:380)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1690)
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:403)
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:266)
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:930)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.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:660)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
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:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
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:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
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:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
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:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
This should not happen because rowKey="#{row.fruitId}" is used with the given <p:dataTable>.
The exception disappears only when the rowKey attribute is removed and the getRowKey() and the getRowData() methods are implemented in the associated managed bean as follows.
#Override
public Object getRowKey(Fruit fruit) {
return fruit != null ? fruit.getFruitId() : null;
}
#Override
public Fruit getRowData(String rowKey) {
List<Fruit> fruits = (List<Fruit>) getWrappedData();
Integer value = Integer.valueOf(rowKey);
for (Fruit fruit : fruits) {
if (fruit.getFruitId().equals(value)) {
return fruit;
}
}
return null;
}
Is it mandatory in the newest version of PrimeFaces (5.2 final) which was not needed in the previous version of PrimeFaces (5.1 final)?
Tested on Mojarra 2.3.0-m02. I presumed that there should not be any relevance with this version of Mojarra.
As mentioned in this link pointing to the PrimeFaces Community Forum,
We changed that part by design cause the rowKey attribute handling
with a LazyDataModel is not correct.
Those two methods getRowKey() and getRowData() need to be implemented in the associated managed bean whenever LazyDataModel<T> is used as shown in the question.
From PrimeFaces User Guide (PDF) - (5.1 (page 164) and 5.2 (page 166)) :
Lazy Loading is an approach to deal with huge datasets efficiently,
regular ajax based pagination works by rendering only a particular
page but still requires all data to be loaded into memory. Lazy
loading datatable renders a particular page similarly but also only
loads the page data into memory not the whole dataset. In order to
implement this, you’d need to bind a
org.primefaces.model.LazyDataModel as the value and implement load
method and enable lazy option. Also it is required to implement
getRowData and getRowKey if you have selection enabled.
The attribute rowKey may be used, when lazy is disabled -- is set to false (default) and row selection is enabled.
From PrimeFaces User Guide (PDF) - (5.1 (page 159) and 5.2 (page 161)) :
RowKey should a unique identifier from your data model and used by
datatable to find the selected rows. You can either define this key by
using the rowKey attribute or by binding a data model which
implements org.primefaces.model.SelectableDataModel.
Such as,
<p:dataTable var="car"
value="#{carBean.cars}"
selection="#{carBean.selectedCars}"
rowKey="#{car.id}">
<p:column selectionMode="multiple"/>
<!--columns-->
</p:dataTable>
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.
I have two classes that there is a relationship # OneToMany (Pay and Split) the code below:
#Entity
#Table(name="pagamento")
public class Pagamento implements Serializable { //Class Pay
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name="idpagamento")
private int id;
...
#ManyToOne()
#JoinColumn(name="idconta")
private Divida coddivida;
and below class Split
#Entity
#Table(name="divida")
public class Divida implements Serializable{
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "idconta")
private int id;
...
#OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="coddivida", targetEntity = Pagamento.class)
private List<Pagamento> pagamento;
And I search through the data code below:
public List<Divida> getDividas(){
return getCleanListOfObjects(Divida.class,"from Divida divida");
}
And I'm trying to display in a datatable is as below:
<p:dataTable id="paneluser" value="#{dividaFaces.listofDivida}" var="divida" selection="#{dividaFaces.selectedDivida}"
rowKey="#{divida.id}" selectionMode="sigle" emptyMessage="Não existe Dívida" paginator="true" rows="10">
<f:facet name="header">
Panel de Dívidas Cadastradas
</f:facet>
<p:column headerText="Descricão">
#{divida.descricao}
</p:column>
<p:column id="pagar" headerText="Tela de Pagamento">
<p:commandButton value="Pagar">
<p:ajax oncomplete="pagetela.show()" update="telapgamento"/>
</p:commandButton>
</p:column>
<f:facet name="footer">
Financé v#{sistema.VERSION}
</f:facet>
</p:dataTable>
But it is giving the error below:
Hibernate:
/*
from
Divida divida */ select
divida0_.idconta as idconta0_,
divida0_.datadeinicio as datadein2_0_,
divida0_.descricaodespesa as descrica3_0_,
divida0_.empresa as empresa0_,
divida0_.exercicio as exercicio0_,
divida0_.observacao as observacao0_,
divida0_.operacaobancaria as operacao7_0_,
divida0_.parcela as parcela0_,
divida0_.tipolancamento as tipolanc9_0_,
divida0_.vencimento as vencimento0_
from
divida divida0_
Lista de Dividas: []
Hibernate:
/*
from
Divida divida */ select
divida0_.idconta as idconta0_,
divida0_.datadeinicio as datadein2_0_,
divida0_.descricaodespesa as descrica3_0_,
divida0_.empresa as empresa0_,
divida0_.exercicio as exercicio0_,
divida0_.observacao as observacao0_,
divida0_.operacaobancaria as operacao7_0_,
divida0_.parcela as parcela0_,
divida0_.tipolancamento as tipolanc9_0_,
divida0_.vencimento as vencimento0_
from
divida divida0_
Mar 26, 2013 8:34:31 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
SEVERE: Error Rendering View[/menu/principal.xhtml]
java.lang.ClassCastException: br.com.finance.model.Divida cannot be cast to java.util.List
at org.primefaces.component.datatable.DataTable.findSelectedRowKeys(DataTable.java:977)
at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:624)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:234)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:196)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:82)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:881)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:851)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:439)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Can anyone help me?
You are using selectionMode="sigle". Please notice the missing 'n' in single. The exception you are encoutering here has nothing to do with Hibernate.
I have a datatable inside confirmDialog, I try to put multipleSelection checkbox on it but causing error & data not visible
page:
<h:form>
<p:commandButton update="msgfiles" actionListener="#{globalCounter.reloadList()}"
oncomplete="choose.show()"/>
<p:confirmDialog widgetVar="choose">
<p:dataTable id="msgfiles" var="obj" rows="5" value="#{globalCounter.objectList}"
rowKey="#{obj[0]}" selection="#{globalCounter.selectedObjectList}">
<p:column selectionMode="multiple"/>
<p:column headerText="id">
<h:outputText value="#{obj[0]}"/>
</p:column>
<p:column headerText="name">
<h:outputText value="#{obj[1]}"/>
</p:column>
</p:dataTable>
</p:confirmDialog>
</h:form>
bean:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
#ManagedBean(name = "globalCounter")
#SessionScoped
public class TestBean implements Serializable {
private List<Object[]> objectList;
public List<Object[]> getObjectList() {
return objectList;
}
public void setObjectList(List<Object[]> objectList) {
this.objectList = objectList;
}
public void reloadList() {
objectList = new ArrayList<Object[]>();
objectList.add(new Object[]{"1", "one"});
objectList.add(new Object[]{"2", "two"});
objectList.add(new Object[]{"3", "three"});
objectList.add(new Object[]{"4", "four"});
objectList.add(new Object[]{"5", "five"});
}
private List<Object[]> selectedObjectList;
public List<Object[]> getSelectedObjectList() {
return selectedObjectList;
}
public void setSelectedObjectList(List<Object[]> selectedObjectList) {
this.selectedObjectList = selectedObjectList;
}
}
error message:
[#|2012-10-03T16:28:36.390+0700|SEVERE|glassfish3.0.1|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=29;_ThreadName=Thread-1;|javax.faces.FacesException
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:86)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at atiits.filter.AuthenticateAuthorize.doFilter(AuthenticateAuthorize.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473)
at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at java.lang.reflect.Array.newArray(Native Method)
at java.lang.reflect.Array.newInstance(Array.java:52)
at org.primefaces.component.datatable.feature.SelectionFeature.decodeMultipleSelection(SelectionFeature.java:53)
at org.primefaces.component.datatable.feature.SelectionFeature.decode(SelectionFeature.java:39)
at org.primefaces.component.datatable.DataTableRenderer.decode(DataTableRenderer.java:53)
at javax.faces.component.UIComponentBase.decode(UIComponentBase.java:790)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:224)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
at javax.faces.component.UIForm.processDecodes(UIForm.java:216)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1042)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:941)
at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
... 32 more
|#]
[#|2012-10-03T16:28:36.390+0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=29;_ThreadName=http-thread-pool-8080-(1);|StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at java.io.Writer.write(Writer.java:140)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:119)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at atiits.filter.AuthenticateAuthorize.doFilter(AuthenticateAuthorize.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473)
at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
|#]
[#|2012-10-03T16:28:36.390+0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_ThreadID=29;_ThreadName=http-thread-pool-8080-(1);|StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException
at java.io.Writer.write(Writer.java:140)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200)
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:119)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at atiits.filter.AuthenticateAuthorize.doFilter(AuthenticateAuthorize.java:100)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:473)
at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:341)
at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:84)
at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:161)
at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:137)
at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:88)
at com.sun.grizzly.http.TaskBase.run(TaskBase.java:189)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
at java.lang.Thread.run(Thread.java:619)
|#]
If I remove <p:column selectionMode="multiple" style="width:18px" /> from the page everything is fine and data displayed
Where did I go wrong?
Primefaces 3.4/ Mojarra 2.0.2 (FCS b10)/Glassfish 3.0.1
I had the same problem and I solved it using <h:form> and <p:ajax>
<p:dataTable id="msgfiles" var="obj" rows="5" value="#{globalCounter.objectList}" rowKey="#{obj[0]}" selection="#{globalCounter.selectedObjectList}">
<p:ajax event="rowSelectCheckbox" process="#this"/>
<p:ajax event="rowUnselectCheckbox" process="#this"/>
<p:ajax event="toggleSelect" process="#this"/>
</p:dataTable>
That should force your component to populate the array in your bean
I had similar issues and I solved it using <p:ajax>.
First I would do as akoskm says and have a unique row key.
Then I would use an array (List[]) (List is more generic than ArrayList) for selectedItems
And finally you can add:
<p:dataTable ...>
<p:ajax event="rowSelectCheckbox" process="#this"/>
<p:ajax event="rowUnselectCheckbox" process="#this"/>
<p:ajax event="toggleSelect" process="#this"/>
</p:dataTable>
Just make sure you have an <h:form> around the table
That will make sure that the component pushes the data to the bean.
Your problem is very similar to this one:
Primefaces datatable: Unable to retrieve selected rows and selection get lost with pagination.
I would try to use
rowKey="#{obj}" as key.
Im trying to populate a JSF Datatable with data that I am retrieving from a DynamoDB Table (The Amazon NoSQL DB). At the moment everything is working fine right up to the Iteration over the scanResults. The debugger shows that my scanResult has a list of all the accounts but when I try to iterate over those results in order to construct my List nothing seems to be added to the allUserSummary List and I end up with a nullpointer exception.
The basic User POJO:
public class User {
private String uuid;
public User(String uuid) {
this.uuid = uuid;
}
}
The managed bean:
private List<User> allUserSummary;
private List<String> uuid;
private User selectedUser;
public List<User> getAllUserSummary() throws Exception {
populateData();
return allUserSummary;
}
private void populateData() throws Exception {
// Create a new AmazonDynamoDBClient and mapper
AmazonDynamoDBClient client = dynamoClient.getDynamoClient();
DynamoDBMapper mapper = new DynamoDBMapper(client);
try {
// Create a new scan expression and filter to find the required data from the db
DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
Map<String, Condition> scanFilter = new HashMap<String, Condition>();
Condition scanCondition = new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL);
scanFilter.put("uuid", scanCondition);
scanExpression.setScanFilter(scanFilter);
// Run the scan
List scanResults = mapper.scan(UserAccounts.class, scanExpression);
// Iterate over the scanned results and add the required data to a new User
for (Iterator it = scanResults.iterator(); it.hasNext();) {
allUserSummary.add(new User(scanResults.get(1).toString()));
}
} catch (Exception e) {
// TODO
}
}
The Datatable (Im using primefaces but the problem is the same with standard JSF DT):
<h:form>
<pou:dataTable id="users"
var="user"
value="#{accountManager.allUserSummary}"
paginator="true"
rows="10"
selection="#{accountManager.selectedUser}">
<f:facet name="header">
UUID
</f:facet>
<pou:column selectionMode="multiple" />
<pou:column headerText="Uuid">
#{user.uuid}
</pou:column>
<f:facet name="footer">
<pou:commandButton id="multiViewButton"
value="View"
icon="ui-icon-search"
update=""
oncomplete=""/>
</f:facet>
</pou:dataTable>
</h:form>
STACK TRACE:
java.lang.IllegalArgumentException: ""
at javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:570)
at org.primefaces.util.ComponentUtils.findClientIds(ComponentUtils.java:244)
at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:222)
at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeMarkup(CommandButtonRenderer.java:81)
at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeEnd(CommandButtonRenderer.java:53)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at org.primefaces.component.datatable.DataTableRenderer.encodeFacet(DataTableRenderer.java:839)
at org.primefaces.component.datatable.DataTableRenderer.encodeTFoot(DataTableRenderer.java:823)
at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:247)
at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:224)
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:108)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:380)
at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:680)
here you go...
Set values into update="" and oncomplete="" or remove them from your button...
<pou:commandButton id="multiViewButton"
value="View"
icon="ui-icon-search"
update=""
oncomplete=""/>
EDIT
try the following changes :
private List<User> allUserSummary = new ArrayList<User>();
.
.
.
#PostConstruct
public void populateData() throws Exception {
.
.
.
.
public List<User> getAllUserSummary() throws Exception {
return allUserSummary;
}