3 Replies Latest reply on Mar 29, 2008 2:55 AM by matt.drees

    Factory method question

    haefti

      Hi!


      I have a select box which is filled by a stateless session bean. To be sure the list of select items is not null I use a method with @Factory to get the data from the database in the appropriate member (latestPictureList).


      If I choose one item and proceed with another method of the bean to show details of the selected entry the factory method is called again (even twice) although I don't need this data for the detailed view of the selected element.


      What do I have to change if I only want to query the database when the selectbox is displayed? (I know that @DataModel outjects as well but I think I need it to get the list in the select box or am I wrong?)


      The session bean:



      @Stateless
      @Name("pictureManager")
      public class PictureManagerAction implements PictureManager {
      /* ...logger and entity manager injection left out */     
           @DataModel
           private List<Picture> latestPictureList;
           
           @Factory("latestPictureList")
           public void initLatestPictureList() {
                  Query query = em.createQuery("select p from Picture p").setMaxResults(100);
                  latestPictureList =  query.getResultList();
           }
      }



      Thanks!

        • 1. Re: Factory method question
          barbacena

          Scope yout @Factory to PAGE (or CONVERSATION).



          import static org.jboss.seam.ScopeType.PAGE
          ...
          @Factory(value = "latestPictureList", scope = PAGE)
          


          • 2. Re: Factory method question
            haefti

            Thanks for the hint but now I get a


            java.lang.IllegalArgumentException: factory method with defined scope outjected a value: latestPictureList


            Did I miss something else?

            • 3. Re: Factory method question
              matt.drees

              Right, you probably want a page-scoped DataModel.  As is, it's Event-scoped.  So when JSF restores the view prior to navigating to the detail page, it will need to re-query your @factory.



              The scope should be specified in the @DataModel annotation, not the @Factory annotation.