0 Replies Latest reply on Nov 24, 2010 5:14 AM by Dmitry Volkov

    Starting long running conversation in PostConstruct method and RichFaces.

    Dmitry Volkov Newbie

      Hello,
      i am using weld 1.0.1, Glassfish 3.0.1, RichFaces 4.0.0M4 and have some problems. There is my bean:


      @Named
      @ConversationScoped
      public class PartnerList implements Serializable {
      
          @Inject
          private PartnerManager pm;
          
          @Inject
          private Conversation conversation;
          
          private List<Partner> all;
      
          @PostConstruct
          private void loadPartnerList() {
              conversation.begin();
              all = pm.loadAll();
          }
          
          public List<Partner> getAll() {
           return all;
          }
      }



      And view:


      <!-- skipped -->
      <h:form prependId="false">
           <rich:dataScroller id="scr" for="table"/>
           <rich:extendedDataTable value="#{partnerList.all}" frozenColumns="1"
                var="element" id="table" 
                style="height:400px; width:100%;" selectionMode="single" rows="20">
                          <!-- skipped -->
           </rich:extendedDataTable>
              </h:form>
      <!-- skipped -->



      The problem is: the conversation is created each time I do paging with rich:dataScroller.
      I have found the solution here, and added a method to the bean:


       public void listener(ComponentSystemEvent event) {
                 if (conversation.isTransient()) {
                 //this code is newer executed
                  conversation.begin();
                 }
          }


      and



      <f:metadata>
               <f:event type="preRenderView" listener="#{partnerList.listener}"/>
       </f:metadata>



      to the view.


      conversation.begin() in beforePhase will newer executed, because conversation was already started in loadPartnerList and conversation.isTransient() always returns false, but somehow it helps. Why just conversation.begin() in PostConstruct doesn't work? Is there more elegant way to solve this problem without f:event and beforePhase?