4 Replies Latest reply on Jun 12, 2007 1:28 PM by pmuir

    Session problems

      Hi

      I have a problem with sessions and JBoss Seam. I have a facelet which displays a collection of objects. In the EJB3 bean related to the facelet, I have a the @Factory() annotation which initalizes the collection with the apropriate objects. So far so good.

      The objects from the collection get listed in a h:dataTable and I have some s:links after the collection entries, which call a method in another bean and pass the selection.

      If I set the Scope of the EJB3 bean which handles the collection to SESSION I can call the foreign method and pass the object. It works. But, if i click on another facelet, and then click back on the origin facelet, the collection doesn't get reloaded. If I change now the Scope to CONVERSATION, the reload of the collection works, but the parameter which is passed to the method (in the s:link) is always null.

      How can I handle this problem?

      @Stateful
      @Scope(ScopeType.CONVERSATION)
      @Name("partsListFinder")
      public class PartsListFinderBean implements PartsListFinder {
       @In(required=false)
       private String plName;
      
       @DataModel
       private List<PartsList> partsLists;
      
       @PersistenceContext(type=PersistenceContextType.EXTENDED)
       private EntityManager em;
      
       public void findPartsList() {
       partsLists = em.createQuery("from PartsList pl where pl.name like :name")
       .setParameter("name", plName + '%')
       .getResultList();
       }
      
       @Factory("partsLists")
       public void findPartsLists() {
       partsLists = em.createQuery("from PartsList").getResultList();
       }
      
       @Destroy @Remove
       public void destroy() { }
      }
      
      <h:dataTable value="#{partsLists}" var="pl">
       <h:column><f:facet name="header">Search Job Name</f:facet> #{pl.name}</h:column>
       <h:column>
       <f:facet name="header">Action</f:facet>
       <s:link value="Edit" action="#{partsListEditor.edit(pl)}"/><br />
       <s:link value="View" action="#{partsListViewer.view(pl)}"/>
       </h:column>
      </h:dataTable>
      
      


        • 1. Re: Session problems
          fernando_jmt

          You can use a page action to refresh your list (when using SESSION scope).

          Like this:

          Stateful
          @Scope(ScopeType.SESSION)
          @Name("partsListFinder")
          public class PartsListFinderBean implements PartsListFinder {
           @In(required=false)
           private String plName;
          
           @DataModel
           private List<PartsList> partsLists;
          
           @PersistenceContext(type=PersistenceContextType.EXTENDED)
           private EntityManager em;
          
           public void findPartsList() {
           partsLists = em.createQuery("from PartsList pl where pl.name like :name")
           .setParameter("name", plName + '%')
           .getResultList();
           }
          
           @Factory("partsLists")
           public void findPartsLists() {
           partsLists = em.createQuery("from PartsList").getResultList();
           }
           public void reload(){
           partsList = null;
           }
           @Destroy @Remove
           public void destroy() { }
          }
          

          Pages.xml:
           <page view-id="/PartsList.xhtml" action="#{partsListFinder.reload}">
           </page>
          


          • 2. Re: Session problems

            Thank you very much, that worked wonderful. Unfortunately I ran into another problem.

            I have two EJBs and two facelets. Both EJBs have a collection (named inventoryObjects) which are annoted as DataModels (@DataModel). Both EJBs are Stateful with a SESSION scope.

            When I now open a facelet which works with the mentioned collection and then switch to the other facelet, I get a LazyInitializationException. This makes sense to me, because I have already a inventoryObjects collection instantiated and filled with some data from the database. How can I now avoid (beside rename all fields to different names) this problem?

            thanks for your help
            thierry

            • 3. Re: Session problems
              fernando_jmt

              I don't understand you very well, nevertheless I avoided the LazyInitializationException using SMPC and this in my faces-config:

              
               <lifecycle>
               <phase-listener>org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener</phase-listener>
               </lifecycle>
              
              
              
              


              • 4. Re: Session problems
                pmuir

                 

                "thierry.rietsch" wrote:
                beside rename all fields to different names


                This is the sane solution.