1 2 Previous Next 18 Replies Latest reply on Mar 1, 2008 12:23 PM by pmuir

    Seam enhancement: Support <leave-conversation> tag in pages.xml

      We would like to request an enhancement in Seam to provide support for a <leave-conversation/> tag (similar to <begin-conversation/> and <end-conversation/>) in pages.xml to leave a long-running conversation. We had a situation recently with a in-house Seam/JSF application where:



      • the application renders a page with a hyperlink as part of a long-running conversation say C1.




      • When the user clicks the hyperlink, the application should process the request in the same long-running conversation C1




      • Once the action is executed, leave the long-running conversation C1




      • Perform a redirect to the view-id that the hyperlink pointed to.




      • The new page should open up in a new long-running conversation.



      In order to leave the original long-running conversation C1, we raise a custom conversation.leaveEvent through pages.xml and then, call the Conversation.leave() Seam API in action listener for conversation.leaveEvent. An easier and more ideal approach here would be to use <leave-conversation/> tag in pages.xml to leave the conversation.

        • 1. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
          gonzalad

          Same need here.


          We also call conversation.setTimeout(0) to make sure conversation is cleared.

          • 2. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml

            Same need here.

            We also call conversation.setTimeout(0) to make sure conversation is cleared.


            Gonzalez, why wouldn't you use inside your navigation rule:


            <end-conversation before-redirect="true"/>



            This will end the conversation and start a new temporary conversation (which you could promote to long-running) after the redirect.

            • 3. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
              gonzalad


              Gonzalez, why wouldn't you use inside your navigation rule:

              <end-conversation before-redirect="true"/>




              This will end the conversation and start a new temporary conversation (which you could promote to long-running) after the redirect.

              Because I need to start immediately a new long running conversation.


              I'd also prefer to minimize redirect usage when possible (in order to improve end user experience).


              I use this mechanism in my main menus links (i.e. each functional area of my application needs a long running conversation).

              • 4. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                gonzalad

                Another point is that since I use nested conversations, if I use the


                <end-conversation before-redirect="true"/>



                in pages.xml, it basically end the most nested conversation (am I right ?)


                And I need to end the root conversation (in order to maximize cleanup).

                • 5. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                  pmuir

                  Gonzalez Adrian wrote on Feb 27, 2008 07:01 PM:



                  Gonzalez, why wouldn't you use inside your navigation rule:

                  <end-conversation before-redirect="true"/>




                  This will end the conversation and start a new temporary conversation (which you could promote to long-running) after the redirect.


                  Because I need to start immediately a new long running conversation.



                  This is not supported in Seam. The only supported model is to end the current conversation in the current request, and start a new conversation in the next request. Anything else may have unknown side effects. Jacob's solution is correct for the OP AFAICS.

                  • 6. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                    gonzalad

                    Thanks Pete and Jacob,


                    This model is allright when I don't use nested conversations.


                    Using nested conversations, I can only rely for now on conversation timeout for cleanup.


                    Is it possible to imagine in the future a built-in mechanism in Seam to end root conversations ?


                    In this case, I could, as Jacob suggested :


                    <end-root-conversation before-redirect="true"/>



                    And start a new one on the redirect.

                    • 7. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml

                      And I need to end the root conversation (in order to maximize cleanup).

                      Yes, it pops the conversation stack.  To perform cleanup of the entire conversation stack you would need to end the root.  This can be accomplished through the approach described in this article.


                      You could do this in an action prior to the redirect.  There is a JIRA issue for direct support of this:  JBSEAM-1943.  Sorry I forget the JIRA link short-hand...


                      Another option is to simply not propagate the conversation and let it timeout according to the conversation-timeout setting.  This allows the user to return to the page through the back-button for a period of time (which is generally the recommended approach).

                      • 8. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                        gonzalad

                        Thanks very much Jacob,


                        I've voted for the JIRA issue, since it's pretty close to what I need (I'll just cope with the redirect vs render issue).


                        I'll modify my code to be better aligned with the tutorial.


                        Thanks once more !




                        • 9. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                          gonzalad

                          Sorry,


                          I'll have one last question (this wasn't my thread at the beginning ).


                          Do you know why we always need to use redirect for ending a long running conversation a for starting a new one ?


                          I currently use the non supported method (leaving root conversation, setting timeout to 0 and creating a new one) and it works pretty well.


                          Here's some code :


                              
                          public void endAllConversationsAndBeginLongRunning() {
                                  log.debug("endAllConversationsAndBeginLongRunning -> conversationId : {0}", Conversation.instance().getId());
                                  Conversation.instance().root();
                                  if (Conversation.instance().isLongRunning()) {
                                      Conversation.instance().setTimeout(1);
                                      Conversation.instance().leave();
                                  }
                                  Conversation.instance().begin();
                                  log.debug("endAllConversationsAndBeginLongRunning <- conversationId : {0}", Conversation.instance().getId());
                              }
                          


                          • 10. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                            keithnaas

                            You need to redirect because the Conversation because Ending the conversation doesn't immediately end it.  Instead it demotes it to a temporary conversation.  In the case of JSF, this temporary conversation is then over when the render response phase is completed.  A beforeRedirect will allow the first conversation to end as soon as the redirect is sent to the browser.  When the browser requests the redirect page, a new conversation is started.

                            • 11. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml

                              Yes, Keith is absolutely right.


                              The reason your leave conversation approach has worked is because a leave() initializes a new temporary conversation and switches to that conversation placing the long-running conversation in the background.  You could then feasibly promote that new temporary conversation to long-running (which I assume is what you are doing).


                              Setting the timeout of the root for the previous long-running conversation as you are causes the root conversation to timeout since it has been placed in the background.  As Pete mentioned this could lead to risky side-effects since it is not a supported approach.


                              Hope that helps.

                              • 12. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                                gonzalad

                                Ok, I've fully understood (that's why I put leave instead of end in my code).


                                My point was that for my usage I don't see any functional value introducing a redirect to do the same I'm currently doing with a render.


                                Since it works (ok, we don't know the side effects for the moment), if this piece of functionnality has really some value (1), perhaps the Seam team could investigate and could support this kind of functionnality if it has no side effects.


                                I can go for the redirect solution instead of the render I'm using but for my use case, it's just introducing more complexity and an additional interaction with the browser.


                                (1) I really don't know the value of this functionnality. I use it quite frequently, but it's my first Seam project, so I'm really no reference on the subject ;).

                                • 13. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml

                                  Going back to the original topic of this thread, could I request comments on the request for Seam enhancement in pages.xml?

                                  • 14. Re: Seam enhancement: Support <leave-conversation> tag in pages.xml
                                    keithnaas

                                    My 2cents:



                                    • Even though the end-conversation element causes the conversation to end, the view is able to be rendered in a consistent state since it is still participating in the current conversation.  What happens if the conversation is left and the view is rendered without a redirect?  Are beans reinitialized before the view is rendered? 




                                    • A Conversation scoped component that injects an entityManager would likely be bug prone if this was used.




                                    • Lets say the current component is Conversation scoped.  That component is used to determine page navigation since it is used as an EL expression somewhere in the navigation rules.  Since the conversation was left, and a new temporary one has been created, what is the value of that EL expression when the navigation handler goes to evaluate it?




                                    • A Conversation is defined as a unit of work from the point of view of the user.  The introduction of leave-conversation would not seem to match with that definition. 



                                    Anyone else?


                                    1 2 Previous Next