问题
I'm trying to make a table filter using Primefaces 5, but the filtering dosn't occur and get the follow stack:
java.lang.NullPointerException at org.primefaces.component.datatable.feature.FilterFeature.filter(FilterFeature.java:136) at org.primefaces.component.datatable.feature.FilterFeature.encode(FilterFeature.java:105) at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:77) at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903) at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559) at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) at org.primefaces.component.api.UIData.visitTree(UIData.java:692) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1740) at javax.faces.component.UIComponent.visitTree(UIComponent.java:1740) at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399) at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:319) 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:1896) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:425) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) 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:647) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at com.star.AuthFilter.doFilter(AuthFilter.java:42) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652) at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)
I'm cloning the primefaces showcase example but i'm not getting it right!
here is my code: xhtml file:
<p:dataTable id="tbl" var="sim" value="#{simulationLog.simulation}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
paginator="true" rows="10" style="margin-bottom:20px"
filteredValue="#{simulationLog.filtredSimulation}"
>
<p:column filterBy="#{sim.simId}" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<p:commandLink value="#{sim.simId}" />
</p:column>
backing bean:
@ManagedBean
@SessionScoped
public class SimulationLog implements Serializable {
.
.
.
private List<SimulationLog> simulation;
private List<SimulationLog> filtredSimulation;
public List<SimulationLog> getSimulation() {
return ParamsDAO.getSimulation(codeAgence);
}
public List<SimulationLog> getFiltredSimulation() {
return filtredSimulation;
}
public void setFiltredSimulation(List<SimulationLog> filtredSimulation) {
this.filtredSimulation = filtredSimulation;
}
.
.
.
}
回答1:
I had the same error and could fix it by wrapping the dataTable with a <h:form>.
回答2:
In short, I had the following and was causing the same error:
<f:facet name="header">Date</f:facet>
<f:facet name="filter">
<h:outputText value="Year: " />
<p:selectOneMenu onchange="PF('myTable').filter();">
<f:selectItem itemValue="" itemLabel="All" />
<f:selectItems value="#{bean.conditionalYears}" var="yearSelect" itemValue="#{yearSelect.value}" itemLabel="#{yearSelect.label}" />
</p:selectOneMenu>
</f:facet>
I had to remove everything from <f:facet name="filter" /> except the <p:selectOneMenu />
In my case, the <h:outputText /> (not limited to outputText) was causing ClassCastException in FilterFeature:277 that were swallowed by UIData.visitTree(VisitContext, VisitCallback) (doesn't have CATCH)
filterValue = ((ValueHolder) filterFacet).getLocalValue();
For some reason, filterFacet is an UIPanel, not a SelectOneMenu as expected.
So, the answer is:
If you are using <f:facet name="filter" />, then try removing everything from it except your custom filter field.
来源:https://stackoverflow.com/questions/24765075/primefaces-datatable-filtering-not-working