5 Replies Latest reply on Jan 2, 2008 5:50 AM by Breako Beats

    One Seam component calling another

    Breako Beats Newbie

      Hi,
      I know it is very easy for a JSP or XHTML to refer to a Seam component through an EL. However I am wondering how one Seam component refers to another? I do not wish to have one Seam component instantiating another, I wish one to look the other up, similar to EJB?
      Any ideas?
      Thanks in advance

        • 1. Re: One Seam component calling another
          Sebastien Degardin Newbie

          Hello,


          As far I know, there are 2 ways :

          1: use @In annotation. (recommended)

          2: use Component.getInstance() (from non-seam component)

          Have a look for options in booth technique.

          Correct if I'm wrong.
          Cheers,

          • 2. Re: One Seam component calling another
            Breako Beats Newbie

             

            "sdegardin" wrote:

            1: use @In annotation. (recommended)

            Thanks for your suggestion. I used the @In annotation but the problem is that the second Seam component does not get it's Seam managed EntityManager set up correctly.

            Basically, I have two Seam components both involved in the same transacation. Both Seam Components have Seam managed EntityManagers and because there are involved in the same transaction, the persistence context should be propagated and shared.

            First Seam Component:

            @Name("manager")
            @Scope(CONVERSATION)
            public class ManagerPojo {
            
             @In
             private EntityManager em;
            
             @In (required=false, value="instancegenerator", create=true)
             private InstanceGeneratorPOJO instanceGeneratorPOJO;
            
             @Begin(join=true, flushMode=FlushModeType.MANUAL)
             public void persist() {
             //...
             instanceGeneratorPOJO.getNextInstance("Person");
             //...
             }
            
             //...
            }
            


            Second Seam Component:
            @Name("instancegenerator")
            @Scope(CONVERSATION)
            public class InstanceGeneratorPOJO {
             @In
             private EntityManager entityManager;
            
             public Long getNextInstance(String type) {
             //...
             }
            
            }
            


            When persist() is invoked I get:

            15:50:41,937 FATAL [application] org.jboss.seam.RequiredException: @In attribute requires non-null value: instancegenerator.entityManager
            javax.faces.el.EvaluationException: org.jboss.seam.RequiredException: @In attribute requires non-null value: instancegenerator.entityManager
            


            Note: If I remove the create=true in the first Seam component, i.e.

             @In (required=false, value="instancegenerator")
             private InstanceGeneratorPOJO instanceGeneratorPOJO;
            


            the instanceGenerator reference is null and I get a Null pointer exception in the persist() method

            anybody got any ideas?



            • 3. Re: One Seam component calling another
              Gerardo Segura Newbie

              Hi,
              it could be just the different variable name:

              private EntityManager em;

              and
              private EntityManager entityManager;


              regards

              • 4. Re: One Seam component calling another
                Sebastien Degardin Newbie

                 

                "gsegura" wrote:
                Hi,
                it could be just the different variable name:

                private EntityManager em;

                and
                private EntityManager entityManager;


                regards


                and if you don't want to use component name has field name, specify the component name in the "value" parameter of the In annotation

                @In(value="em") private EntityManager entityManager;


                Cheers,

                • 5. Re: One Seam component calling another
                  Breako Beats Newbie

                  Thanks for the replies, you spotted my mistake.
                  Happy New Year!