我需要在jsp代碼中手動實例化ManagedBean。我用下面的代碼:自動創建ManagedBean問題
FacesContext context = FacesContext.getCurrentInstance();
ActorBean bean = (ActorBean) context.getApplication().createValueBinding("#{actorBean}").getValue(context);
response.getWriter().print(bean.getChaine());
但我仍然得到一個NullPointerException! 。:( 任何建議,請
這是stacktracelog:。
11 juin 2010 12:33:44 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: "Servlet.service()" pour la servlet jsp a généré une exception
java.lang.NullPointerException
at org.apache.jsp.jspx.portal_jsp._jspService(portal_jsp.java:157)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
主要想法是能夠將JSF值傳遞給javascript函數。我使用的是AJAX框架(EXT JS),我需要使用json API轉換數據,以EXTjs的圖形組件進行通信。所以問題是..我堅持JSF架構(MVC),我不能只通過ManagedBeans訪問數據。 這是我想要做的一個例子: Ext.onReady(function(){ Ext.MessageBox.alert('#{bean.prop}'); }); 但是,javascript無法評估jsf值。這是可能的與jsp。 使用JSON轉換器等會變得更加複雜。 – Debbech 2010-06-11 13:52:27
你真的**需要通過'FacesServlet'傳遞請求。使其成爲JSF頁面。然後你可以使用''。或者,從JSP升級到Facelets。然後你可以使用'#{bean.prop}'內聯。另請參閱[Java/JSP/JSF和JavaScript](http://balusc.blogspot.com/2009/05/javajspjsf-and-javascript.html)。 –
BalusC
2010-06-11 13:54:48
謝謝,我得到的主要想法,但我仍然從服務器收到空var當我嘗試顯示此: var variableFromServer ='' 你有任何想法爲什麼? –
Debbech
2010-06-11 14:55:31