如何修复java.lang.IllegalArgumentException:null source?

时间:2014-06-03 20:09:43

标签: spring jsf java-ee model-view-controller primefaces

我们有一个使用JSF2 Primefaces和Spring的应用程序。该应用程序工作正常。但是当我将图表添加到xhtml文件中时会发生这种情况:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui"
    template="/template.xhtml">
    <ui:define name="content">

            <p:chart type="pie" model="#{Statistique.pieChart}" title="Tache Critique et Non Critique"style="width:400px;height:300px"  />

    </ui:define>
</ui:composition>

这是堆栈跟踪:

juin 03, 2014 7:58:24 PM org.apache.catalina.core.StandardWrapperValve invoke
Grave: Servlet.service() for servlet [Faces Servlet] in context with path [/HCP] threw exception [null source] with root cause
java.lang.IllegalArgumentException: null source
    at java.util.EventObject.<init>(Unknown Source)
    at javax.faces.event.SystemEvent.<init>(SystemEvent.java:67)
    at javax.faces.event.ComponentSystemEvent.<init>(ComponentSystemEvent.java:69)
    at javax.faces.event.PostRestoreStateEvent.<init>(PostRestoreStateEvent.java:69)
    at com.sun.faces.lifecycle.RestoreViewPhase.deliverPostRestoreStateEvent(RestoreViewPhase.java:256)
    at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:245)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:107)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:114)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:308)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

这是Statistique组件:

@Scope("session")
@Component("Stats")
public class StatsImpl implements Statistique  {
    @Autowired
    private TacheService tacheService;
    private PieChartModel pieChart;
    private List<Tache> listTaches;
    public StatsImpl (){


    construct,getter and seters ...
    @Transactional
    public PieChartModel getStats()
    {
        listTaches=(List<Tache>) tacheService.loadTaches();
        int critique=0;
        int nomCritique=0;
        for(int i=0;i<listTaches.size();i++)

        {

            if(listTaches.get(i).getType().equals("Critique"))critique++;
            else nomCritique++;
        }
        pieChart.set("Tache Critique", critique);
        pieChart.set("Tache Non Critique", nomCritique);
        return pieChart;
    }

    }

1 个答案:

答案 0 :(得分:0)

我注意到的一些事情: 1.需要使用类名Statistique.pieChart的小写字母调用Jsf Bean约定应该是statistique.pieChart

  1. 如果这是您正在使用的bean,您应该给他打电话statsImpl.pieChart
  2. Jsf 2支持依赖注入,因此您可能希望使用而不是spring bean。只是为了让你考虑保持秩序。
  3. 我建议你看一下Spring + Jsf + Hibernate简单项目的本教程。确保你也这样做。

    希望有所帮助

    编辑:

    据我所知,你不能用jsf页面调用spring bean。你需要使用jsf bean,但我不确定,无论如何我建议使用jsf以避免恼人的问题。它只需要节省你的时间。