11 Replies Latest reply on Jul 9, 2007 7:24 AM by harpritt

    @Factory annotation

    harpritt

      Hi

      Appologies if i use the wrong terms to descibe my current problem, im new to SEAM and im just about keeping my head above water

      I have 4 dropdown menus that i wish to populate with SelectItem Objects.

      I decided the best way (limited knowledge) was to use the @Factory annotation to define the 4 components in a Stateful Session.... and then retrieve them using the #{component1} etc in the drop downs.
      (my Stateful session bean contains 4 @Factory annotations)

      ... Problem is that only one of the components contains any data in the scope so the JSF page complains about requiring not null components.

      in the end i settled for standard accessors as below. Any advice as to where i was going wrong wiht the @Factory annotation would be very helpful. Many Thanks


      @Stateful
      @Name("GsmsCrManager")
      
      @Local(GsmsCrsManager.class)
      @Remote(GsmsCrsManager.class)
      
      
      public class GsmsCrManagerImpl {
      
      
       public SelectItem[] getCrReasons() {
       SelectItem[] crReasons = new SelectItem[7];
       crReasons[0] = new SelectItem("Correction of Error or Omission");
       crReasons[1] = new SelectItem("Clarification of Existing Content");
       crReasons[2] = new SelectItem("New Content");
       crReasons[3] = new SelectItem("Change in Operating Procedures");
       crReasons[4] = new SelectItem("Change in Regulations");
       crReasons[5] = new SelectItem("Change in Equipment");
       crReasons[6] = new SelectItem("Change in Organisation");
       return crReasons;
       }
      
       public SelectItem[] getCrActions() {
       SelectItem[] crActions = new SelectItem[5];
       crActions[0] = new SelectItem("Create a New document");
       crActions[1] = new SelectItem("Edit Existing document");
       crActions[2] = new SelectItem("Delete Existing document");
       crActions[3] = new SelectItem("Move Existing document");
       crActions[4] = new SelectItem("Request an action not covered by the above");
       return crActions;
       }
      
      
       public SelectItem[] getCrAudience() {
       SelectItem[] crAudience = new SelectItem[5];
       crAudience[0] = new SelectItem("Crew");
       crAudience[1] = new SelectItem("sdfsd");
       crAudience[2] = new SelectItem("asda");
       crAudience[3] = new SelectItem("asd
       crAudience[4] = new SelectItem("sdfgdsfg");
       return crAudience;
       }
      
      
       public SelectItem[] getCrAudienceReviewalUrgency() {
       SelectItem[] crAudienceReviewalUrgency = new SelectItem[5];
       crAudienceReviewalUrgency[0] = new SelectItem("High");
       crAudienceReviewalUrgency[1] = new SelectItem("Medium/High");
       crAudienceReviewalUrgency[2] = new SelectItem("Medium");
       crAudienceReviewalUrgency[3] = new SelectItem("Low/Medium");
       crAudienceReviewalUrgency[4] = new SelectItem("Low");
       return crAudienceReviewalUrgency;
       }
      
       @Destroy @Remove
       public void destroy(){
      
      }
      }


        • 1. Re: @Factory annotation
          pmuir

          Take a look at s:selectItems, and the ui example - it gives you cleaner ui/backing layer separation.

          • 2. Re: @Factory annotation
            harpritt

            Cheers man ill give it a look

            Any idea about the use of multiple @factory annotations in a stateless bean?

            Cheers again Pete

            • 3. Re: @Factory annotation
              pmuir

              Post what you are trying to do with @Factory, then I can tell you what is wrong :)

              • 4. Re: @Factory annotation
                harpritt

                That is some VERY cool stuff! especially the

                <framework:entity-query name="continents" ejbql="select c from Continent c" />

                in components.xml

                ....... im going to look up to see if i can use an XML file to populate the entity rather than a ejbql query

                VERY VERY FLIPPING COOL!!!! I LOVE THIS STUFF....

                • 5. Re: @Factory annotation
                  harpritt

                  Hi Pete

                  I was trying to do this... below

                  the only difference between this and what i actually did was that my multiple @Factory annotations were in a stateless session bean.... I was calling all 3 from a single UI page. The crappy problem i had was that only one of the 3 @Factory variables got added to the scope..... and seam ui complained about a needing a not null variable... I wish i could explain it better ....


                  
                  import org.jboss.seam.annotations.Factory;
                  import org.jboss.seam.annotations.Name;
                  
                  @Name("UiStuff")
                  public class UiStuff
                  {
                  
                   @Factory("ages")
                   public int[] getAges() {
                   int[] ages = {18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
                   return ages;
                   }
                  
                   @Factory("names")
                   public String[] getNames() {
                   int[] names= {"jim","john","tom","mick","bodger","badger"};
                   return names;
                   }
                  
                   @Factory("reallyRandom")
                   public String[] getRandomness() {
                   int[] randomIt= {"john ketly","is","a","weather","man"};
                   return randomIt;
                   }
                  
                  }


                  • 6. Re: @Factory annotation
                    pmuir

                    It should work just fine like this, or in a SLSB. Sounds like its working now anyway. Post back if you have more problems.

                    • 7. Re: @Factory annotation
                      harpritt

                      nice one pete

                      you rock

                      • 8. Re: @Factory annotation
                        ellenzhao

                        maybe the code

                        int[] names= {"jim","john","tom","mick","bodger","badger"};
                        


                        should be like
                        String[] names= {"jim","john","tom","mick","bodger","badger"};
                        


                        And the int[] type in your first method is a bit tricky if you want to do null test....I would like to use the Integer[] or better yet, List in your case....

                        Regards,
                        Ellen

                        • 9. Re: @Factory annotation
                          ellenzhao

                          I mean List. :-)

                          • 10. Re: @Factory annotation
                            ellenzhao

                             

                            List<Integer>
                            


                            • 11. Re: @Factory annotation
                              harpritt

                              Cheers Ellen

                              Lol.... i was copying and pasting like made ... lol i must have missed that one.... its was fine in my app though..

                              lol... cheers dude