2 Replies Latest reply on Feb 8, 2008 12:03 PM by norman.richards

    @In and @Factory

    gersonk

      Code example:

      ...
      @Name("componentA")
      @Stateful
      public class ComponentA{
      
       @In(required=false)
       @Out(required=false, scope=PAGE)
       private Integer x;
      
       @Factory("x")
       public void initX(){
       x = 1;
       }
      
       public void someMethod(){
       ... // why is 'x' null here?
       }
      
      }
      


      How I can tell Seam to invoke the Factory Method whenever someMethod() is called if 'x' is null?


        • 1. Re: @In and @Factory
          nickarls

           

          if (x == null) {
           initX();
          }
          


          ;-)

          If think that if someMethod is called before "x" has been referenced, it can be null.

          • 2. Re: @In and @Factory

            Factories are not for initializing your state for your own use. You could probably self-inject x or call Component.getInstance() or something. If you are really trying to expose that state outside your object and need it internally, put an @Create on that @Factory method.