ValueChangeListener问题与空指针异常

时间:2012-06-10 17:00:34

标签: jsf-2 facelets icefaces-2

在SelectOneMenu组件中使用ValueChangeListener时遇到错误。我不确定是由于导致此问题的方法还是由于xhtml无法找到该方法。

ERROR

12:54:10,815 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http--127.0.0.1-8080-7) JSF1073: javax.faces.event.AbortProcessingException caught during processing of APPLY_REQUEST_VALUES 2 : UIComponent-ClientId=j_idt6:j_idt18, Message=/reportPage.xhtml @48,185 valueChangeListener="#{statusReport.retrieveReport}": java.lang.NullPointerException
12:54:10,818 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (http--127.0.0.1-8080-7) /reportPage.xhtml @48,185 valueChangeListener="#{statusReport.retrieveReport}": java.lang.NullPointerException: javax.faces.event.AbortProcessingException: /reportPage.xhtml @48,185 valueChangeListener="#{statusReport.retrieveReport}": java.lang.NullPointerException
    at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:157) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
    at javax.faces.event.ValueChangeEvent.processListener(ValueChangeEvent.java:134) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
    at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:769) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:759) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:935) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.10.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.10.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.10.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.10.Final.jar:]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.0.Final.jar:7.1.0.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_25]
Caused by: java.lang.NullPointerException
    at com.weeklyreport.bean.StatusReport.retrieveReport(StatusReport.java:163) [classes:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_25]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_25]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.6.0_25]
    at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.6.0_25]
    at org.apache.el.parser.AstValue.invoke(AstValue.java:262) [jbossweb-7.0.10.Final.jar:]
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278) [jbossweb-7.0.10.Final.jar:]
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) [jsf-impl-2.1.5-jbossorg-1.jar:2.1.5-SNAPSHOT]
    at javax.faces.event.MethodExpressionValueChangeListener.processValueChange(MethodExpressionValueChangeListener.java:144) [jboss-jsf-api_2.1_spec-2.0.0.Final.jar:2.0.0.Final]
    ... 22 more

xhtml代码

<ice:panelGroup
                style="border: 1px solid black; background-color: #F0ECEB;padding: 10px; text-align: left;height=20pix;">
                <ice:selectOneMenu value="#{statusReport.projectDetID}" valueChangeListener="#{statusReport.retrieveReport}" onchange="this.form.submit()"  immediate="true" style="width: 150px;" > 
                    <f:selectItem itemLabel="Select One" itemValue="" />
                    <f:selectItems value="#{statusReport.listOfProjectDetail}"
                        var="projectDetail" itemLabel="#{projectDetail.project}              #{projectDetail.startDate}   -    #{projectDetail.endDate}"
                        itemValue="#{projectDetail.pdetailId}" />
                </ice:selectOneMenu>

            </ice:panelGroup>

bean代码

public void retrieveReport(ValueChangeEvent event){

    System.out.println(" Processing ...code..");
    @SuppressWarnings({ "unchecked", "unused" })
    List<ProjectDetail> listOfProjectDet1 = (List<ProjectDetail>) projectDetailFacade.find(projectDetID);
    System.out.println("project details size" + listOfProjectDet1.size());
    System.out.println("Generated Data:Completed");

}

如何解决?

1 个答案:

答案 0 :(得分:0)

以下任何一项都为空

1 - &gt; projectDetailFacade为空

List<ProjectDetail> listOfProjectDet1 = (List<ProjectDetail>) projectDetailFacade.find(projectDetID); 

2 - &gt; listOfProjectDet1为空

System.out.println("project details size" + listOfProjectDet1.size());

检查哪一个为空,修复该问题应解决您的问题。