4 Replies Latest reply on May 27, 2009 10:04 AM by giunad

    bijection test - not working

    giunad

      Hi,


      I'm facing this problem: after autentication, a new bean is created and put into seam context. the bean is an account bean that should be accesible from everywhere.


      so I'm testing bijection in a simple case: 2 form. the first one create the bean marked with @Out and the second one get it with @In.


      I miss some thing. I get the following error:





      Caused by: org.jboss.seam.RequiredException: @Out attribute requires non-null value: myform.myentity
           at org.jboss.seam.Component.outjectAttribute(Component.java:1731)
           at org.jboss.seam.Component.outjectAttributes(Component.java:1722)
           at org.jboss.seam.Component.outject(Component.java:1575)
           at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:86)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.persistence.EntityManagerProxyInterceptor.aroundInvoke(EntityManagerProxyInterceptor.java:29)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.persistence.HibernateSessionProxyInterceptor.aroundInvoke(HibernateSessionProxyInterceptor.java:31)
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
           at org.jboss.seam.intercept.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:50)
           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:597)
           at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:118)
           at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.entity.ExtendedPersistenceContextPropagationInterceptor.invoke(ExtendedPersistenceContextPropagationInterceptor.java:57)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
           at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
           at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
           ... 114 more


      here is the first bean



      @Stateful
      @Name("myform")
      public class MyformBean implements Myform {
           
           @Out
           MyEntity myentity;
      
           private String value;
      
           public void myform() {
                myentity = new MyEntity();
                myentity.setName("form value: "+value);
           }
      
           public String getValue() {
                return value;
           }
      
           public void setValue(String value) {
                
                this.value = value;
           }
      
           @Destroy
           @Remove
           public void destroy() {
           }
      
      }
      



      and the second one



      @Stateful
      @Name("MyForm2")
      public class MyForm2Bean implements MyForm2 {
      
           @In
           MyEntity myentity;
      
           private String value;
      
           public void myForm2() {
                System.out.println("MyForm2.myForm2(): " + myentity.getName());
           }
      
           public String getValue() {
                return value;
           }
      
           public void setValue(String value) {
                this.value = value;
           }
      
           @Destroy
           @Remove
           public void destroy() {
           }
      
      }



      entity bean is a bean with just one property: name.


      It seams to me that all I do is very similar to what I read on tutorial and forums. Yes.. it's driving me crazy..


      Just one note: in jboss log I see


      22:26:13,912 WARN DeploymentInfo Only the root deployment can set the loader repository, ignoring config LoaderRepositoryConfig repositoryName: seam.jboss.org:loader mytest, repositoryClassName: org.jboss.mx.loading.HeirarchicalLoaderRepository3, configParserClassName: org.jboss.mx.loading.HeirarchicalLoaderRepository3ConfigParser, repositoryConfig: java2ParentDelegation false


      Could a class loader error explain all that?


      Any help will be very appreciated.
      (sorry for my english)

        • 1. Re: bijection test - not working
          niox.nikospara.yahoo.com

          Hello,


          myentity is created in myform(). This method should be called as a JSF action. How is it called? Is it called at all?


          Then, myentity will be bound to the conversation scope (@Out outjects to component scope, component is SFSB, thus scope=CONVERSATION). If the conversation is not long running-it doesnt seem to be, you will encounter problems with the @In too. Try @Out(scope=...).


          I guess the classloader warning is caused because you are trying to set the loader repository from the war, which included in an ear. Move the code to jboss-app.xml like:


          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE jboss-app
               PUBLIC "-//JBoss//DTD J2EE Application 4.2//EN"
               "http://www.jboss.org/j2ee/dtd/jboss-app_4_2.dtd"
          >
          <jboss-app>
               <loader-repository>seam.jboss.org:loader=mytest</loader-repository>
          </jboss-app>
          



          I dont believe this is relevant to your problem though.

          • 2. Re: bijection test - not working
            giunad

            Hello


            first of all thanks for the quick reply.


            both form and form2 have an input text and a submit button.
            so when I click for submit, a new istance is required and constructor creates myentity.
            however you are right: a jsf action whould have been a better test.


            I tried with scope.session but i got the same error.


            that's all.

            • 3. Re: bijection test - not working
              niox.nikospara.yahoo.com

              Could you post the page code? I believe the error is trivial.


              The error message says that myentity was null, when SEAM tried to outject it. This may be caused by one of the following reasons:


              1) myform() was never called


              2) myform() was called on an instance, then another method was called on a different instance, for which myentity was null


              3) myform() was called outside of SEAM (I am not sure about how this may happen, if it can happen at all)



              Anyway, I think posting the page code will help.

              • 4. Re: bijection test - not working
                giunad

                Solved!!!


                The problem is that I cannot access injected bean in constructor but only in methods.


                So if you do


                constructor(){
                System.out.println(myentity);
                }


                you can read: null


                if you do


                method(){
                System.out.println(myentity);
                }


                you can read:entity-to-string-rapresentation


                btw I also changed the code in


                @Out MyEntity myentity  new MyEntity();


                However I must read carefully the doc explaining all that.



                ps
                thanks nikos,
                a beer is waiting for you in rome!
                :D