2 Replies Latest reply on Aug 6, 2009 6:04 PM by asookazian

    Restarting a LRC

    asookazian

      refers to this post in Seam forum:


      http://seamframework.org/Community/RestartingALRCInSeam3


      can we restart LRCs and/or stop then start LRCs in Web Beans and is the redirect required like it is in Seam 2?

        • 1. Re: Restarting a LRC
          nickarls

          Well, the Conversation context lifecycle secion of the spec speaketh:



          The conversation associated with a JSF request is determined at the beginning of the restore view phase and does not change during the request

          Which implies the redirect. You can start/stop (LRC boolean flag) the conversation as many times you like (but not change the conversation if) but it is only processed at the begin and end of the request as I see it.

          • 2. Re: Restarting a LRC
            asookazian

            This means that a dynamic re-association of a LRC to the current HTTP request is not possible.  Which in most cases is acceptable (I'm not sure if I can actually think of a use case where we would need to programmatically re-associate a new cid or different cid for a request, not including the workspace switcher scenario).


            So let's examine the HtmlSelectOneMenu case step-by-step.


            <h:selectOneMenu value="#{listManagement.selectedListValueForList}">
                                     <s:selectItems  var="list"
                                               value="#{listManagement.getLists()}"
                                               label="#{list.displayName}"
                                               noSelectionLabel="Please Select..."/>                                                                                
                                     <s:convertEntity />
                                     <a4j:support event="onchange" action="#{listManagement.populateDataTable}"/>
                                </h:selectOneMenu>



            1) user navigates to URL, JSF page rendered.


            2) user selects a new value from the HtmlSelectOneMenu component.


            3) onchange, a4j:support action method is executed


            4) via Conversation API, temporary conversation is promoted to LRC when action method successfully completes


            5) page redirects to itself (postback)


            6) user selects a different value from the HtmlSelectOneMenu component.


            ************ now we want to end and begin a new LRC so we can avoid manually clearing all the state/data
            associated with the components in that LRC and PC/SMPC **********************


            7) demote conversation using @End(beforeRedirect=true) or Conversation API and redirect page in pages.xml to same page


            8) start new LRC after redirect


            So what about a @Restart(redirect="mypage.xhtml") annotation?  That would essentially do all the above in these types of use cases?  Basically demote active LRC to temporary conversation for subsequent destruction by container, redirect to specified page, start a new LRC.


            Otherwise, the programmer has to re-use the same LRC (via @Begin(join=true)) and handle all the cleanup when the user selects a new value in the drop down to make sure the slate is wiped clean in terms of component state, PersistenceContext cache, etc.


            Sorry, this is not 100% Web Beans specific, but the problem/concept and solution applies for both Seam and Web Beans as we are dealing with conversation management essentially.