7 Replies Latest reply on Dec 27, 2006 6:12 PM by hstang

    Could not instantiate Seam component error

    lle

      Hi,

      I have a conversation scope action class, which has a bijectional conversation-scope object as a DataModelSelection. When I executed an ajax4jsf request (from an a4j:commandLink), I always get the following exception:

      org.jboss.seam.InstantiationException: Could not instantiate Seam component: selectedSession
       at org.jboss.seam.Component.newInstance(Component.java:1722)
       at org.jboss.seam.Component.getInstance(Component.java:1625)
       at org.jboss.seam.Component.getInstance(Component.java:1592)
       at org.jboss.seam.jsf.SeamVariableResolver.resolveVariable(SeamVariableResolver.java:46)
       at org.apache.myfaces.trinidadinternal.el.TrinidadVariableResolver.resolveVariable(TrinidadVariableResolver.java:52)
       at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:134)
       at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:68)
       at com.sun.el.parser.AstValue.getValue(AstValue.java:107)
       at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
       at javax.faces.component.UIData.getValue(UIData.java:1023)
       at org.apache.myfaces.component.html.ext.HtmlDataTableHack.createDataModel(HtmlDataTableHack.java:437)
       at org.apache.myfaces.component.html.ext.HtmlDataTable.createDataModel(HtmlDataTable.java:847)
       at org.apache.myfaces.component.html.ext.HtmlDataTableHack.getDataModel(HtmlDataTableHack.java:414)
       at org.apache.myfaces.component.html.ext.HtmlDataTable.getDataModel(HtmlDataTable.java:839)
       at org.apache.myfaces.component.html.ext.HtmlDataTableHack.getRowCount(HtmlDataTableHack.java:87)
       at javax.faces.component.UIData.processColumnChildren(UIData.java:689)
       at javax.faces.component.UIData.processDecodes(UIData.java:585)
       at org.apache.myfaces.component.html.ext.HtmlDataTable.processDecodes(HtmlDataTable.java:293)
       at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:605)
       at javax.faces.component.UIForm.processDecodes(UIForm.java:56)
       at org.ajax4jsf.framework.ajax.AjaxViewRoot.processDecodes(AjaxViewRoot.java:353)
       at org.apache.myfaces.lifecycle.ApplyRequestValuesExecutor.execute(ApplyRequestValuesExecutor.java:32)
       at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:147)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._invokeDoFilter(TrinidadFilterImpl.java:326)
       at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:290)
       at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:213)
       at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:90)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:75)
       at org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:213)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:46)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:32)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: java.lang.InstantiationException: com.ga.riskapp.session.GASession
       at java.lang.Class.newInstance0(Class.java:335)
       at java.lang.Class.newInstance(Class.java:303)
       at org.jboss.seam.Component.instantiateJavaBean(Component.java:1045)
       at org.jboss.seam.Component.instantiate(Component.java:1008)
       at org.jboss.seam.Component.newInstance(Component.java:1718)
       ... 60 more

      Here is the action class code snippet:
      @Name("detailsearch")
      @Scope(ScopeType.CONVERSATION)
      @GALoggedIn
      public class GAAccountDetailsAction {
      
       @In
       private Session gadb;
       @In
       private GAHostAppInfo hostApp;
       @In
       private FacesMessages facesMessages;
       @Logger
       private Log log;
       @DataModel
       private List<GASession> sessionList;
       @DataModelSelection
       @In(required=false) @Out(required=false)
       private GASession selectedSession;
      
       public void applyScale1() {
       try {
       this.scale = 1;
       getSessions();
       } catch (Throwable t) {
       log.error("Error while applying scale", t);
       facesMessages.addFromResourceBundle(Constants.APPLICATION_ERROR);
       }
       }
      ...
      }

      Here is the GASession class:
      @Name("selectedSession")
      @Scope(ScopeType.CONVERSATION)
      public class GASession {
      ...
      }
      

      Anyone knows why such an exception thrown? When I accessed the debug page, I saw the "selectedSession" object existed in the "detailsearch". So, I am not sure why such an exception thrown.
      Thanks.

        • 1. Re: Could not instantiate Seam component error

          Hi,

          Does your GASession class have a default no-arg constructor?

          • 2. Re: Could not instantiate Seam component error
            lle

            No, it doesn't because my app controls the instantiation of this class with some init values. I don't want Seam to create it. The context variable should point to an existing GASession with @DataModelSelection. Why does Seam need to instantiate this component?

            • 3. Re: Could not instantiate Seam component error

              Because somewhere in your code or view, you are referencing "selectedSession" which is a Seam component (you gave it a @Name)

              • 4. Re: Could not instantiate Seam component error
                lle

                Yes, my view does reference the context variable "selectedSession".

                1. Since GASession is a Seam component, it will be instantiated by Seam even if the context variable already exists. Is that correct?

                2. If I provide a default no-args constructor, this exception will go away? Then, do I have to provide an @Create method to initialize the GASession object created by Seam? This is where I don't understand. If Seam will instantiate a new instance of this component, then will it refers to the correct instance currently selected by @DataModelSelection?

                Thanks.

                • 5. Re: Could not instantiate Seam component error

                  This looks very suspicious to me:

                   @DataModelSelection
                   @In(required=false) @Out(required=false)
                   private GASession selectedSession;
                  


                  Why are you trying to inject it?


                  • 6. Re: Could not instantiate Seam component error
                    lle

                    It's because initially that object is injected from another page. However, I have changed to use page action.
                    Even if I removed the @In(required=false), the same exception occurs.

                    I can provide a no-args constructor as suggested by hstang. However I'd like to understand the behavior of Seam to avoid further issues.

                    Thanks.
                    ly

                    • 7. Re: Could not instantiate Seam component error

                      If you provide a no-args constructor, the exception dealing with instantiation will be gone. This is the only way Seam can construct your seam components properly. Yes, as you suggested, use the @Create to initialize other important properties pertaining to the class. The annotated method is called once Seam has fully initialize the component.

                      As for @DataModel, this will outject the annotated property to the scope of the owning component. In your case, the conversation.

                      And for @DataModelSelection, this will inject the selected model object, if it's successfully look up in the contexts. You have to ensure that the conversation is long-running, just long enough though, so that @DataModelSelection object can be successfully be retrieved through the @DataModel property.