我们有一个使用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. Jsf Bean约定需要用类名的小写字母来调用Statistique.pieChart
应该是statistique.pieChart
- 如果这是你正在使用的bean,你应该叫他
statsImpl.pieChart
- Jsf 2支持依赖注入,因此您可能希望使用spring bean而不是spring bean。只是为了让你考虑一下保持秩序。
我建议你看看这个教程如果Spring + Jsf + Hibernate简单的项目。请确保你也在做同样的事情。
希望有帮助
编辑:就我所知,你不能用jsf page调用spring bean。你需要使用jsf bean,但我不确定,无论如何,我建议使用jsf,以避免恼人的问题。这只需要节省你的时间。