Primefaces数据表过滤不起作用

时间:2014-07-15 18:01:51

标签: jsf-2 primefaces

我正在尝试使用Primefaces 5制作表格过滤器, 但过滤不会发生并得到以下堆栈:

  

java.lang.NullPointerException at   org.primefaces.component.datatable.feature.FilterFeature.filter(FilterFeature.java:136)     在   org.primefaces.component.datatable.feature.FilterFeature.encode(FilterFeature.java:105)     在   org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:77)     在   javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1903)     在   com.sun.faces.context.PartialViewContextImpl $ PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:559)     在   com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183)     在org.primefaces.component.api.UIData.visitTree(UIData.java:692)at   javax.faces.component.UIComponent.visitTree(UIComponent.java:1740)at at   javax.faces.component.UIComponent.visitTree(UIComponent.java:1740)at at   com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:399)     在   com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:319)     在   org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60)     在   javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:1004)     在javax.faces.component.UIComponent.encodeAll(UIComponent.java:1896)     在   com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:425)     在   com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)     在   com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)     在com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)at   com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)     在javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)     在   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在com.star.AuthFilter.doFilter(AuthFilter.java:42)at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)     在   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)     在   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)     在   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)     在   org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)     在   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)     在   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)     在   org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)     在   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)     在   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)     在   org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1015)     在   org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:652)     在   org.apache.coyote.http11.Http11NioProtocol $ Http11ConnectionHandler.process(Http11NioProtocol.java:222)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.doRun(NioEndpoint.java:1575)     在   org.apache.tomcat.util.net.NioEndpoint $ SocketProcessor.run(NioEndpoint.java:1533)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745)

我正在克隆素数展示example,但我没有把它弄好!

这是我的代码: xhtml文件:

<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>

支持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;
    }
    .
    .
    .
}

2 个答案:

答案 0 :(得分:12)

我遇到了同样的错误,可以通过用<h:form>包装dataTable来修复它。

答案 1 :(得分:0)

简而言之,我有以下内容并导致同样的错误:

<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>

我必须删除<f:facet name="filter" />以外的所有内容,<p:selectOneMenu />

除外

在我的情况下,<h:outputText />(不限于outputText)导致{em> FilterFeature:277 中的ClassCastExceptionUIData.visitTree(VisitContext, VisitCallback)吞没(不是有CATCH)

filterValue = ((ValueHolder) filterFacet).getLocalValue();

由于某些原因,filterFacetUIPanel,而不是预期的SelectOneMenu

所以答案是: 如果您使用的是<f:facet name="filter" />,请尝试删除自定义过滤器字段以外的所有内容。