org.primefaces.component.datatable.feature.SortFeature.multiSort中的java.lang.NullPointerException

时间:2015-04-16 14:34:45

标签: jsf jsf-2 primefaces

当我尝试对我的primefaces数据表进行排序时,我总是遇到异常:

16:28:01,771 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost-127.0.0.1-8099-3) Error Rendering View[/pages/requests.xhtml]: java.lang.NullPointerException
at org.primefaces.component.datatable.feature.SortFeature.multiSort(SortFeature.java:173) [primefaces-5.2.jar:5.2]
at org.primefaces.component.datatable.feature.SortFeature.encode(SortFeature.java:104) [primefaces-5.2.jar:5.2]
at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:78) [primefaces-5.2.jar:5.2]
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:517) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) [jsf-impl-2.1.16-jbossorg-1.jar:]
at org.primefaces.component.api.UIData.visitTree(UIData.java:821) [primefaces-5.2.jar:5.2]
at javax.faces.component.UIComponent.visitTree(UIComponent.java:1623) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:378) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:298) [jsf-impl-2.1.16-jbossorg-1.jar:]
at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:60) [primefaces-5.2.jar:5.2]
at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:979) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:411) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124) [jsf-impl-2.1.16-jbossorg-1.jar:]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.16-jbossorg-1.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.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.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]

16:28:01,818 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ecad-web].[Faces Servlet]] (http-localhost-127.0.0.1-8099-3) Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalStateException: CDATA tags may not nest
at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.startCDATA(HtmlResponseWriter.java:664) [jsf-impl-2.1.16-jbossorg-1.jar:]
at javax.faces.context.ResponseWriterWrapper.startCDATA(ResponseWriterWrapper.java:172) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at javax.faces.context.PartialResponseWriter.startError(PartialResponseWriter.java:342) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.Final]
at org.primefaces.context.PrimePartialResponseWriter.startError(PrimePartialResponseWriter.java:190) [primefaces-5.2.jar:5.2]
at com.sun.faces.context.AjaxExceptionHandlerImpl.handlePartialResponseError(AjaxExceptionHandlerImpl.java:200) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.context.AjaxExceptionHandlerImpl.handle(AjaxExceptionHandlerImpl.java:124) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119) [jsf-impl-2.1.16-jbossorg-1.jar:]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.16-jbossorg-1.jar:]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.9.Final.jar:2.0.9.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.Http11AprProcessor.process(Http11AprProcessor.java:897) [jbossweb-7.0.13.Final.jar:]
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:626) [jbossweb-7.0.13.Final.jar:]
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:2039) [jbossweb-7.0.13.Final.jar:]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_71]

我读过,

并检查了评论:“你有2个问题:1)糟糕的ajax异常处理2)在渲染响应期间做业务逻辑。 - BalusC” - >事实并非如此。不应该有任何例外,我在getter中没有做任何业务逻辑。

xhtml代码:

<p:dataTable id="pendingRequests" var="pendingRequest"
             value="#{requestBean.pendingRequests}"
             rows="5"
             paginator="true"
             rowsPerPageTemplate="5,10,20,50"
             sortMode="multiple">

    <p:column style="width:16px">
        <p:rowToggler />
    </p:column>

    <p:column headerText="Reference"  sortBy="#{pendingRequest.requestReference}">
        <h:outputText value="#{pendingRequest.requestReference}" />
    </p:column>

    <p:rowExpansion>
        <p:panelGrid  columns="2" columnClasses="label,value" >
            <f:facet name="header">
                <h:outputLabel value="Details" />
            </f:facet>

            <h:outputText value="Reference: " />
            <h:outputText value="#{pendingRequest.requestReference}" />
        </p:panelGrid>

        <br/>
        <p:dataTable var="pendingRequestDocument"
                     value="#{pendingRequest.pendingRequestDocuments}">

            <f:facet name="header">
                <h:outputLabel value="Documents" />
            </f:facet>

            <p:column headerText="Stored document">
                <h:outputText value="#{pendingRequestDocument.storedDocument}" />
            </p:column>
        </p:dataTable>
        <br/><br/>
    </p:rowExpansion>
</p:dataTable>

Backingbean:

import java.io.Serializable;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

import be.fgov.health.ecad.domain.request.PendingRequest;
import be.fgov.health.ecad.service.RequestService;

@Named
@SessionScoped
public class RequestBean implements Serializable {

    private static final long serialVersionUID = -6538980904680369808L;
    private List<PendingRequest> pendingRequests;

    @Inject
    private RequestService requestService;

    @PostConstruct
    public void init() {
        pendingRequests = requestService.findAllPendingRequests();
    }

    public List<PendingRequest> getPendingRequests() {
        return pendingRequests;

    }
}

我已经尝试调试getPendingRequests并且它永远不会为null(但它被多次调用,但这是正常的行为..)。

有没有人有任何想法?

  • JSF版本:2.0
  • PrimeFaces版本:5.2

编辑: 出于测试目的,我刚刚在getter中创建了一个新的List(没有调用某些EJB),我也得到了相同的异常。

1 个答案:

答案 0 :(得分:0)

IllegalStateException很可能是红鲱鱼。我也遇到了类似于primefaces的行为。在ajax调用期间发生异常时,就会发生这种情况。

你必须解决根本原因NullPointerException。可能您有null - pendingRequest.requestReference的值。