2 Replies Latest reply on Mar 3, 2009 11:47 AM by Ben Catherall

    Duplicate Factory problem

    MA Poitras Newbie

      I'm trying to setup a Factory in an Ancestor object and then have children inherit from the ancestor object however I keep getting duplicate Factory error.  I guess the factory names must be unique for each child component but since I'm creating the Factory at the ancestor level, I'm not sure how to create an abstract factory.  Anyone have a work around for this problem.  Here is some cleaned-up code.


      Ancestor:


      abstract public class FormCore implements FormCoreInterface {
      
      
           private Boolean isScreenDetailsPropertiesSet = false;
      
          public void initAction() {
               //nothing to do here - this is just a placeholder
          }
      
           @Factory("isScreenDetailsPropertiesSet ")
           public void findIsScreenDetailsPropertiesSet() {
                if (isScreenDetailsPropertiesSet == null || isScreenDetailsPropertiesSet == false) {
                     initAction();
                     isScreenDetailsPropertiesSet = true;
                } 
           }
           
           public void clearFieldsBeforeRedirect() {
                isScreenDetailsPropertiesSet = null;
           }




      This is a child.



      @Stateful
      @Scope(ScopeType.CONVERSATION)
      @Name("accountStatus")
      public class AccountStatusImpl extends FormCore implements AccountStatus, Serializable {
      
        public void initAction() {
        //init screen....  
        }
      }
      



      The application is a sort of wizard where the backend bean remains part of a long running conversation and we want an initialize method to be triggered everytime users go back to a form.

        • 1. Re: Duplicate Factory problem
          Erdem Agaoglu Newbie

          i think @Factory usage in here is a bit inappropriate. Since @Factory will outject a context variable named isScreenDetailsPropertiesSet it will create a confusion if there is more than one component of the same ancestor (so duplicate factory error). Like, which component isScreenDetailsPropertiesSet? i would initialize it with @Create or maybe initAction in your case and access it like #{accountStatus.screenDetailsPropertiesSet}.


          But if you have to use @Factory i think you should override findIsScreenDetailsPropertiesSet in child components and annotate them with different values.

          • 2. Re: Duplicate Factory problem
            Ben Catherall Newbie

            Why not just turn the method in to a getter?


            public boolean isScreenDetailsPropertiesSet() {
                 if (isScreenDetailsPropertiesSet == null || isScreenDetailsPropertiesSet == false) {
                      initAction();
                      isScreenDetailsPropertiesSet = true;
                 } 
            }



            Then in your XHTML you can do


            #{accountStatus.screenDetailsPropertiesSet}