1 Reply Latest reply on Jan 14, 2009 7:16 PM by wrzep

    Factory and Out - why isn't factory method called?

    amayingenta

      Hi, I'm developing a Seam (2.0.2) app using POJOs (running in Tomcat). I've hit an issue where I'm getting the @Out attribute requires not-null value after I removed the required=false from an outjected variable in an attempt to have it initialized when the component that outjects it is created.


      Here is part of the class:


      @Name("workflowHelper")
      @Scope(ScopeType.SESSION)
      @AutoCreate
      public class WorkflowHelper implements Serializable {
      
          @Out
          private List<TravelRequestForm> travelActionList;
      
          @Factory(value="travelActionList", autoCreate=true)
          public void initTravelActionList() {
              // initializes travelActionList here - will never be null
          }
      
          public boolean inActionList(TravelRequestForm travelRequest) {
              return travelActionList.contains(travelRequest);
          }
      }





      The WorkflowHelper class in injected into another class that enforces access control and uses the inActionList(TravelRequestForm) method. This causes the outjection error:


      org.jboss.seam.RequiredException: @Out attribute requires non-null value: workflowHelper.travelActionList
              at org.jboss.seam.Component.outjectAttribute(Component.java:1629)
              at org.jboss.seam.Component.outjectAttributes(Component.java:1620)
              at org.jboss.seam.Component.outject(Component.java:1473)
              at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:47)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
              at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
              at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
              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.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
              at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
              at edu.osu.oit.travel.seam.WorkflowHelper_$$_javassist_7.inActionList(WorkflowHelper_$$_javassist_7.java)
              at edu.osu.oit.travel.seam.TravelSecurity.getDocumentMode(TravelSecurity.java:77)
      



      Why doesn't the Factory method get called in this case to initialize the outjected object? I have found in similar cases that I can cause factory methods to be called by referencing the outjected variable in EL (e.g. in pages.xml), but this seems like a hack.


      Or is it an indication that my design is dodgy? Would I be better to encapsulate the List rather than outjecting it, and call WorkflowHelper.getTravelActionList() which can initialize the data as necessary? Is it this mix of utility methods and outjected attributes that is causing me problems?


      This is my first Seam project, so I'm learning what works by trial and error.


      Thanks, Andrew