0

I am doing a spring bean injection to my jsf managed bean property for which am getting the above mentioned error. The following is the full stack trace:

    SEVERE: Error Rendering View[/sample.xhtml]
 javax.faces.FacesException: Could not retrieve value of component with path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /sample.xhtml][Class: javax.faces.component.html.HtmlForm,Id: j_id1848100722_6e27c746][Class: javax.faces.component.html.HtmlBody,Id: j_id1848100722_6e27c740][Class: javax.faces.component.html.HtmlInputText,Id: j_id1848100722_6e27c7f4]}
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:347)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue(RendererUtils.java:291)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInputBegin(HtmlTextRendererBase.java:169)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java:158)
at org.apache.myfaces.shared_impl.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:75)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:519)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:618)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1159)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
  Caused by: javax.faces.FacesException: java.lang.reflect.InvocationTargetException
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:228)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:303)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:266)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:96)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:67)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:72)
at org.apache.el.parser.AstValue.getValue(AstValue.java:147)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189)
at org.apache.myfaces.view.facelets.el.TagValueExpression.getValue(TagValueExpression.java:85)
at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:243)
at javax.faces.component.UIOutput.getValue(UIOutput.java:71)
at javax.faces.component.UIInput.getValue(UIInput.java:143)
at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getValue(RendererUtils.java:343)
... 30 more
   Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.core.DefaultInstanceManager.postConstruct(DefaultInstanceManager.java:212)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:154)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:146)
at org.apache.myfaces.config.annotation.Tomcat7AnnotationLifecycleProvider.newInstance(Tomcat7AnnotationLifecycleProvider.java:68)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:162)
... 46 more
 Caused by: java.lang.NullPointerException
at common.beans.StartBean.fillTable(StartBean.java:35)
... 55 more

My web xml is the following:

    <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 <display-name>testjsf</display-name>
  <welcome-file-list>
<welcome-file>sample.xhtml</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
 </welcome-file-list>
   <servlet>
     <servlet-name>Faces Servlet</servlet-name>
     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
  </servlet>
<servlet-mapping>
  <servlet-name>Faces Servlet</servlet-name>
  <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
 <context-param>
   <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>resources.application</param-value>
</context-param>
 <context-param>
  <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
  <param-value>false</param-value>
    </context-param>
           <context-param>
               <description>State saving method: 'client' or 'server' (=default). See JSF        Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
    </context-param>
       <context-param>
         <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
   </context-param>
  <context-param>
     <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
     <param-value>true</param-value>
  </context-param>
      <context-param>
          <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
       <param-value>false</param-value>
      </context-param>
     <context-param>
     <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
      <param-value>true</param-value>
      </context-param>
    <listener>
     <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-        class>
   </listener>
           <listener>
                    <listener-class>
                           org.springframework.web.context.ContextLoaderListener
                 </listener-class>
       </listener>

  </web-app>

My application context is the following:

     <?xml version="1.0" encoding="UTF-8"?>

     <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="springb" class="common.springbeans.Springbean">


   </bean>

  </beans>

My faces-config is the following:

    <?xml version="1.0" encoding="UTF-8"?>

<faces-config
   xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee      http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
      version="2.0">

    <managed-bean>
    <managed-bean-name>userbean</managed-bean-name>
    <managed-bean-class>common.beans.StartBean</managed-bean-class>
    <managed-bean-scope>view</managed-bean-scope>
    <managed-property>
        <property-name>ispringBeans</property-name>
        <value>#{springb}</value>
    </managed-property>
</managed-bean>

    <application>
        <el-resolver>
             org.springframework.web.jsf.el.SpringBeanFacesELResolver
       </el-resolver>

      </application>

 </faces-config>

The jars I included are the following: enter image description here

Lastly this is the piece of code where I am trying to inject:

   public class StartBean implements Serializable{

/**
 * 
 */
private static final long serialVersionUID = 1L;
private String value;
private boolean val;
private ArrayList<TestModel> list;
private TestModel tm;
private IDataFillBean bean;
private IspringBeans ispringBeans;


        @PostConstruct
          public void fillTable(){
        setList(new ArrayList<TestModel>(0));

        list = (ArrayList<TestModel>) ispringBeans.fillDatamodel();


    }
   }

It seems a direct injection. Am I missing anything here? Please guide me. Thanks in advance.

EDIT: Now, I removed @postConstruct annotation from the class fillTable, called fillTable from "action" of commandButton and this exception goes off, Does this mean during @postConstruct method call the spring bean still wont be injected into the properties?

h-kach
  • 351
  • 2
  • 8
  • 25
  • I solved it by removing @postConstruct on the method fillTable, Can anyone tell me why is that? – h-kach Jan 23 '13 at 12:30
  • `javax.faces.component.html.HtmlInputText` is missing a value attribute or the value has no getter ? Show us some related xhtml. – Christophe Roussy Jan 23 '13 at 13:36
  • Have you read the root cause of the stack trace? Scroll down the stack trace to the bottommost part. You got just a `NullPointerException` inside `fillTable()` method which means that `ispringBeans` is `null`. You should reframe your question and ask why it is not been injected instead of asking why you got an `InvocationTargetException` (which is far too trivial to answer and completely unrelated to the problem of why the spring bean is not injected). – BalusC Jan 23 '13 at 14:22
  • I saw that. But when I removed @postConstruct it started working. How is that? – h-kach Jan 24 '13 at 05:19
  • Uhm. If you remove `@PostConstruct`, then `fillTable()` will not be invoked, then `ispringBeans` (which is actually `null`) will not be accessed anymore. Does it make sense now? At this point I'd strongly recommend to play around with basic Java first. I have the impression that you've been thrown in deep Java EE hole too early. Learn creeping/walking before running. – BalusC Jan 24 '13 at 20:24
  • @BalusC No, pardon me.I skipped a point here.What I meant was I removed "@postConstruct" and accessed fillTable() from "action" of a commandButton.This worked properly.What I wanted to know was,Does Myfaces call "@postconstruct" method even before injecting all the properties in the bean? – h-kach Jan 25 '13 at 05:51
  • Oh, apparently you end up with multiple instances. Sorry, this is then beyond me. I don't do Spring, just standard Java EE CDI and EJB which is so much easier. I guess that it'll work fine if you manage the bean by Spring instead of by JSF. I believe that you could use `@Component @Scope` to declare it as a Spring managed bean and use `@Autowired` to inject a managed property. – BalusC Jan 25 '13 at 11:59
  • @BalusC hmm.. I used to inject spring beans into JSF bean this way.But to pre-populate data onload of a page, I tried calling the method through the bean which is injected by spring, and it gave this exception, hence I was confused whether Myfaces calls "@postConstruct" method before injection. Also, I dont think I have multiple instances, could you please elaborate? – h-kach Jan 25 '13 at 12:38
  • @BalusC Does this gotta do anything with this? http://mail-archives.apache.org/mod_mbox/myfaces-users/200801.mbox/%3CDAE8AAF8C23423498F74D66B90B08A790C2C27@MSGBOSCLN2WIN.DMN1.FMR.COM%3E . I know its pretty old, even then just a guess. – h-kach Jan 25 '13 at 13:06
  • Look indeed much related. Try upgrading MyFaces or try (temporarily) Mojarra. Or .. maybe drastically .. get rid of legacy Spring and use the modern CDI/EJB which is already provided out the Java EE box. It works as a breeze with JSF and you don't need any XML anymore. – BalusC Jan 25 '13 at 13:12

1 Answers1

0

I have tested with a new application with new eclipse juno having mojarra and it seem to work fine. So the problem turns out to be Myfaces.

h-kach
  • 351
  • 2
  • 8
  • 25