4 Replies Latest reply on Dec 22, 2005 10:25 AM by gavin.king

    CVS Seam and Injecting Stateful Session Beans

      Hi All

      I am using the current version of Seam from CVS.

      I am trying to reproduce the crud code (generated from tool) in my application.
      Whenever I try to inject a Stateful session bean using (@In) I get the following error:

      SEVERE: Error Rendering View
      javax.faces.el.EvaluationException: /showsite.xhtml @23,65 value="#{siteEditor.instance.name}": $Proxy113
       at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:60)
       at javax.faces.component.UIOutput.getValue(UIOutput.java:75)
       at org.apache.myfaces.renderkit.RendererUtils.getStringValue(RendererUtils.java:225)
       at org.apache.myfaces.renderkit.html.HtmlTextRendererBase.renderInput(HtmlTextRendererBase.java:131)
       at org.apache.myfaces.renderkit.html.HtmlTextRendererBase.encodeEnd(HtmlTextRendererBase.java:49)
       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:331)
       at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:521)
       at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:518)
       at com.sun.facelets.FaceletViewHandler.encodeRecursive(FaceletViewHandler.java:518)
       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:447)
       at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:300)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:95)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:44)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
       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.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
       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:856)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
       at java.lang.Thread.run(Thread.java:595)
      Caused by: javax.faces.el.EvaluationException: Bean: $Proxy113, property: instance
       at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:404)
       at org.apache.myfaces.el.PropertyResolverImpl.getValue(PropertyResolverImpl.java:71)
       at com.sun.facelets.el.LegacyELContext$LegacyELResolver.getValue(LegacyELContext.java:137)
       at com.sun.el.parser.AstValue.getValue(AstValue.java:96)
       at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
       at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
       at com.sun.facelets.el.LegacyValueBinding.getValue(LegacyValueBinding.java:56)
       ... 33 more
      Caused by: java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.apache.myfaces.el.PropertyResolverImpl.getProperty(PropertyResolverImpl.java:400)
       ... 39 more
      Caused by: java.lang.IllegalArgumentException: could not inject: siteEditor.contractOperations
       at org.jboss.seam.Component.setFieldValue(Component.java:872)
       at org.jboss.seam.Component.injectFields(Component.java:706)
       at org.jboss.seam.Component.inject(Component.java:564)
       at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:29)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:81)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:46)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:81)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.BusinessProcessInterceptor.manageBusinessProcessContext(BusinessProcessInterceptor.java:59)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:81)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:31)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.seam.util.Reflections.invoke(Reflections.java:13)
       at org.jboss.seam.interceptors.Interceptor.aroundInvoke(Interceptor.java:81)
       at org.jboss.seam.interceptors.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.ejb.SeamInterceptor.aroundInvoke(SeamInterceptor.java:41)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:79)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:65)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:44)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:32)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(M
      17:27:06,532 INFO [STDOUT] ethodInvocation.java:98)
       at org.jboss.ejb3.stateful.StatefulInstanceInterceptor.invoke(StatefulInstanceInterceptor.java:133)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPolicy.invokeInNoTx(TxPolicy.java:53)
       at org.jboss.aspects.tx.TxInterceptor$NotSupported.invoke(TxInterceptor.java:79)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:32)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
       at org.jboss.ejb3.stateful.StatefulContainer.localInvoke(StatefulContainer.java:136)
       at org.jboss.ejb3.stateful.StatefulLocalProxy.invoke(StatefulLocalProxy.java:83)
       at $Proxy113.getInstance(Unknown Source)
       ... 44 more
      Caused by: java.lang.IllegalArgumentException
       at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)
       at java.lang.reflect.Field.set(Field.java:656)
       at org.jboss.seam.Component.setFieldValue(Component.java:868)
       ... 106 more


      The two session beans in question are:

      @Stateful
      @Name("siteEditor")
      @Interceptor(SeamInterceptor.class)
      public class SiteEditor implements ISiteEditor {
      
       private static final long serialVersionUID = 1658701032472430834L;
      
       @In(create=true)
       private EntityManager em;
      
       @In(required=false)
       ContractOperations contractOperations;
      
       private Contract instance = new Contract();
      
       @TransactionAttribute(NOT_SUPPORTED)
       public Contract getInstance() {
       return instance;
       }
       public void setInstance(Contract instance) {
       this.instance = instance;
       }
      
       private boolean isNew = true;
       @TransactionAttribute(NOT_SUPPORTED)
       public boolean isNew() {
       return isNew;
       }
       public void setNew(boolean isNew) {
       this.isNew = isNew;
       }
      
      
      
      
       @Begin
       //@IfInvalid(outcome=Outcome.REDISPLAY)
       public String create() {
       em.persist(instance);
       isNew = false;
       return "edit";
       }
      
       //@IfInvalid(outcome=Outcome.REDISPLAY)
       public String update() {
       return "edit";
       }
      
       @End
       public String delete() {
       em.remove(instance);
       if (contractOperations!=null) contractOperations.find();
       return "find";
       }
      
       @End
       public String done() {
       if (!isNew) em.refresh(instance);
       if (contractOperations!=null) contractOperations.find();
       return "find";
       }
      
       @Destroy @Remove
       public void destroy() {}
      
      
      }
      


      and

      @Stateful
      @Name("contractOperations")
      @Scope(ScopeType.SESSION)
      @Interceptor(SeamInterceptor.class)
      public class ContractOperations implements IContractOperations {
      
       @In(create=true)
       private EntityManager em;
      
       @DataModel
       private List<Contract> contracts;
      
       @DataModelSelection
       private Contract selectedcontract;
      
      
      
      
       /**
       * @see uk.com.millwood.view.IContractOperations#find()
       */
       @SuppressWarnings("unchecked")
       @Factory("contracts")
       public void find() {
       contracts = em.createQuery("from Contract c order by c.id").getResultList();
       }
      
      
       /* (non-Javadoc)
       * @see uk.com.millwood.view.IContractOperations#createContract()
       */
       public String createContract() {
       return "createContract";
       }
      
      
       /**
       * @see uk.com.millwood.view.IContractOperations#deleteContract()
       */
       public String deleteContract() {
       em.remove(selectedcontract);
       find();
       return "viewcontracts";
       }
      
       @Begin
       public String editContract(){
       //siteEditor.setInstance( em.merge(selectedcontract) );
       //siteEditor.setNew(false);
       return "showsite";
       }
      
       /* (non-Javadoc)
       * @see uk.com.millwood.view.IContractOperations#listContracts()
       */
       public String listContracts() {
       return "viewcontracts";
       }
      
       /* (non-Javadoc)
       * @see uk.com.millwood.view.IContractOperations#done()
       */
       public String done() {
       return "viewcontracts";
       }
      
       @Destroy @Remove
       public void destroy() {
       }
      
       /**
       * @see uk.com.millwood.view.IContractOperations#getContracts()
       */
       public List<Contract> getContracts() {
       return contracts;
       }
      
      
      }
      


      I tried to debug the error but I got to the following line in Component.java

      field.set(bean, value);

      in Componet.setFieldValue

      and then obviously I get the throwable. I checked all the instances and it finds the contractOperations wrapped instance, but it stil throws the above exception.

      If anybody could help I would be very appreciative as I am kind of stuck on this.

      I am using todays CVS version of Seam with Jboss 4.0.3SP1. I have even upgraded all relevant hibernate parts to the latest available.


      Thanks

      James

        • 1. Re: CVS Seam and Injecting Stateful Session Beans
          gavin.king

          Does the @Local interface of your stateful bean have a method named getInstance()?

          • 2. Re: CVS Seam and Injecting Stateful Session Beans

            Hi Gavin

            Unfortuneatly my @Local interface does have the getInstance function declaration:

            Here is the local interface for the siteEditor component.

            @Local
            public interface ISiteEditor {

            public boolean isNew();
            public void setNew(boolean isNew);

            public Contract getInstance();
            public void setInstance(Contract instance);

            public String update();
            public String delete();
            public String create();

            public String done();

            public void destroy();
            }


            As I said the exception gets thrown when the contractOperations gets injected into the siteEditor stateful session bean. It finds the bean in the session scope but then when it goes to set the field it throws the following error

            Caused by: java.lang.IllegalArgumentException
             at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)




            • 3. Re: CVS Seam and Injecting Stateful Session Beans

              Hi All

              I solved the problem, it was a very silly mistake on my part:

              I was attempting to inject the full implementation of the stateful session bean rather than the interface. This is obviously what caused the following error.

              Caused by: java.lang.IllegalArgumentException
               at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:63)


              I apologise for wasting your time.

              By the way fantastic job on Seam, it is just what was desperately needed to integrate all the wonderful components coming out of JEMS. I look forward to what will come next.


              Many thanks,

              James

              • 4. Re: CVS Seam and Injecting Stateful Session Beans
                gavin.king

                That was my next guess :)