3 Replies Latest reply on Feb 3, 2010 3:10 PM by Nikos Paraskevopoulos

    Seam Injection Issue

    pushpak1981 Novice

      Hi All,


      I have two Components defined at Application Scoped which are loaded when the server starts (using @startup Annotation). I wanted to access some variables from first component into second component. I have used @out annotation to outject and variable and @In annotation to inject into other component. But i am getting null values when it is injected.


      Component1:
      @Out(scope ScopeType.APPLICATION,value executionService)
      public ExecutionService executionService;


      Component2:
      @In(value executionService)
      public ExecutionService executionService;


      Any Help would be highly appreciated.


      Thanks.

        • 1. Re: Seam Injection Issue
          yachaa Newbie

          The way I do it is as follow: ComponentA is created first


          
          @Name("ComponentA")
          @Scope(ScopeType.APPLICATION)
          @Startup
          public class ComponentA {
              String myProperty;
          
              @Create
              public void onCreate() {
                  myProperty="blah";
              }
          }




          When ComponentB is created, the ComponentA is injected to B


          
          @Name("ComponentB")
          @Scope(ScopeType.APPLICATION)
          @Startup
          @Install(depends="ComponentA")
          public class ComponentB {
          
              @In
              ComponentA a;
          
              @Create
              public void onCreate {
                  System.out.println(a.getMyProperty());
              }
          
          }
          
          



          Hope it helps.




          • 2. Re: Seam Injection Issue
            pushpak1981 Novice

            Thanks for the reply. I tried executing the code but it gives me NullPointerException in componentB while accessing the getMyProperty.The ComponentA is not injected. We are using Seam 2.1.

            • 3. Re: Seam Injection Issue
              Nikos Paraskevopoulos Novice

              Hi,


              Did you try the Factory Components, as described in ch 4.8 of Seam 2.2.0 documentation?