6 Replies Latest reply on Jul 26, 2007 12:37 PM by chawax

    Problem with injection

    chawax

      Hi,

      I try to run a Seam application generated from AndroMDA but I have problems with injection. I have a "employeList" Seam component (CONVERSATION scope) which needs anoter Seam component "serviceEmploye" which is a stateless one.

      My injection code is this one :

      /**
       * Inject Seam session bean ServiceEmploye
       */
       @org.jboss.seam.annotations.In (value="serviceEmploye")
       protected fr.xxx.t4.core.employe.ServiceEmployeLocal serviceEmploye;
      


      But the injection does not work :

      Caused by: org.jboss.seam.RequiredException: In attribute requires value for component: employeList.serviceEmploye
       at org.jboss.seam.Component.getInstanceToInject(Component.java:1920)
       at org.jboss.seam.Component.injectFields(Component.java:1386)
       at org.jboss.seam.Component.inject(Component.java:1156)
       at



      ServiceEmploye component is defined this way in components.xml

      <component
       name="serviceEmploye"
       class="fr.horoquartz.t4.core.employe.ServiceEmployeBean"
       scope="STATELESS"
       jndi-name="t4Seam-1.0-SNAPSHOT/ServiceEmployeBean/local"/>
      


      I am a newbie with Seam. I desperately tried to understand what happens, but I still have not found a solution. So any help would be welcome ;)

        • 1. Re: Problem with injection
          wise_guybg

          Hi chawax,

          I think that you don't have an instance of serviceEmploye created so it cannot be injected. RequiredException, this means that Seam is searching for that instance to inject it.

          There are two possibilities:
          - you create such an instance before you go to the class that needs it
          - you can tell Seam that this injection is not always required (@In(required=false))

          • 2. Re: Problem with injection
            stephen.friedrich

            - or use @In(create=true) to let seam create the component if needed
            - or set the auto-create flag in components.xml:

            <component
             name="serviceEmploye"
             auto-create="true"
            class="fr.horoquartz.t4.core.employe.ServiceEmployeBean"
             scope="STATELESS"
             jndi-name="t4Seam-1.0-SNAPSHOT/ServiceEmployeBean/local"/>


            • 3. Re: Problem with injection
              chawax

              That's what I thought ... I expected that Seam create instance when needed (such as a lightweight container like Spring). So it does not ?

              I tried to add @Startup to ServiceEmploye bean, but I had errors because the component had to be APPLICATION or SESSION scoped.

              About the @In(required=false), does it mean that Seam will instantiate the component if it doesn't exist ?

              • 4. Re: Problem with injection
                wise_guybg

                I think @Startup is used for other tasks

                @In(required=false) will not instantiate... it will leave it to null

                @In(create=true) will instantiate

                In my opinion Seam provides you with all the options you need.

                • 5. Re: Problem with injection
                  chawax

                  OK, I'm going to try @In(create=true)

                  • 6. Re: Problem with injection
                    chawax

                    It works. Thanks a lot ;)