3 Replies Latest reply on Mar 29, 2008 2:55 AM by Matt Drees

    Factory method question

    Tim Morgan Newbie

      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!