4 Replies Latest reply on May 12, 2011 3:34 PM by edoetsch

    Factory and static

    edoetsch

      This worked in JBoss 4.2.3/Seam 2.1.1 but not flunks in 5.1/2.2.1


      This was coded by a previous developer and I am wondering if I am simply do not understand @Factory or if it worked differently previously. This dropdown is giving me the error:
      Expected a child component type of UISelectItem/UISelectItems for component type javax.faces.SelectOne(startDateLimit)


      I left the previous developer's comment in as it implies perhaps something strange was done in earlier versions.




                      <ui:define name="input">
                        <h:selectOneMenu id="startDateLimit" value="#{contractSearchData.startDateLimit}" >
                           <s:selectItems value="#{dateLimits}" var="startDateLimit" label="#{startDateLimit}" />
                        </h:selectOneMenu>      
                      </ui:define>
      
      @Name("contractSearchData")
      @Scope(ScopeType.CONVERSATION)
      public class ContractSearchData extends SessionAwareObject implements Serializable {
      
         // Static var goes into one of the Seam Contexts??
         // When referencing a static var on JSF page, use its name as is, without reference to the component itself,
         // like "dateLimits", not "contractBean.dateLimits".
         // Have to use @Factory for Seam to inject a static var, 
         // because it may need it, like in this case before seam component itself is needed.
         public final static String [] dateLimits = new String[] {"On or Before", "On", "On or After"};
       
         /**
          * @return drop down values for selecting dates
          */
         @Factory("dateLimits")                                                              
         public static String[] getDateLimits() {
            return dateLimits;
         }
      
      }



        • 1. Re: Factory and static
          lvdberg

          Hi,


          I don't think it works on a static method. Test this by just removing the static from the method.


          Leo

          • 2. Re: Factory and static
            edoetsch

            Leo van den Berg wrote on May 11, 2011 17:54:


            Hi,

            I don't think it works on a static method. Test this by just removing the static from the method.

            Leo


            Thanks for the reply, removing static from the method did not work unfortunately. Is it possibly the conversation scope?

            • 3. Re: Factory and static
              aareshchanka

              Select components won't work with arrays, use List.

              • 4. Re: Factory and static
                edoetsch

                Alexandr Areshchanka wrote on May 12, 2011 14:06:


                Select components won't work with arrays, use List.


                I was able to get this to work by moving the @Factory method to another class using SESSION scope. There it looked like:




                   @Factory("dateLimits")                                                              
                   public String[] getDateLimits() {
                      return ContractSearchData.dateLimits;
                   }





                Not sure if that was the sole issue. Perhaps the class to which I moved it was instantiated already keeping the problem from occurring.