8 Replies Latest reply on Mar 8, 2012 10:31 AM by dgsmith2

    how to leave a long running conversation and start a new one

    marcelkolsteren

      In my application I have an action method that needs to leave (not end) the current long running conversation, and start a new one. I tried the following options:


      • annotate the method with @Begin => that doesn't work, because it requires that the current conversation is not long running; adding "join=true" or "nested=true" is no option, because I would like a new, not nested conversation
      • in the JSF page, use the <s:conversationPropagation type="none"> inside the command element to leave the current conversation => that doesn't work either because it ends the current conversation after the restore view phase, which is too early, because the conversation is still needed during the next couple of phases

        I need something like an @Begin(leave-current=true) annotation, but it's not there. Of course, I can call the Seam API in my action method (using Seam's Manager class), but calling the Seam API directly in application code doesn't seem a future-proof solution. I start now with that approach, but I hope that someone has a better idea.


        • 1. Re: how to leave a long running conversation and start a new
          marcelkolsteren

          Leaving the long-running conversation programatically in the action method turns out to be no solution: Seam's ConversationInterceptor throws an IllegalStateException before the method is executed, because the @Begin annotation doesn't specify "join=true". I could try to work around this by registering another action listener to the command button, which fires before the main action method, and which leaves the conversation. That makes the construction even more artificial.

          Anyone who knows an elegant solution?

          • 2. Re: how to leave a long running conversation and start a new
            c_inconnu

            Hi
            I have a similar problem and i am quite new to Seam. Has anyone a solution ?
            marcelkolsteren could you please explain how you did it using the API ?
            Thanks

            • 3. Re: how to leave a long running conversation and start a new
              marcelkolsteren

              Good to know that I'm not the only one who needs this functionality. I posted my solution for switching to another long running conversation on my weblog: http://marcelkolsteren.blogspot.com.

              • 4. Re: how to leave a long running conversation and start a new
                c_inconnu

                Thanks for the input. It is what i was looking for.

                However, it is strange that there is no direct support for this... I was wondering if using one big top level conversation then nested conversations couldn't do the job (i am a noob, remember :) ?

                In fact, my problem is to manage workspace a la eclipse (http://jboss.com/index.html?module=bb&op=viewtopic&t=130054).
                If someone from the Seam team may answer to that question, it will be a real help!

                Thanks anyway

                • 5. Re: how to leave a long running conversation and start a new

                  Folks,

                  We faced a similar situation a few days ago. The user could click on a hyperlink in a page to go to a different page which was required to open in a new non-nested conversation. Before redirecting to the new page, the application was required to process the edits the user had made on the screen, save those changes and not end the conversation (instead, leave the conversation since the user could come back to the first page by back buttoning from the 2nd page).

                  The solution we went with was:

                  1. On the JSP page, use <h:commandLink> to post the form data back to the server so that the POST will propagate conversation.

                  2. Process the form submit using standard JSF phases.

                  3. Determine which page to redirect the user to.

                  4. In phase V, return the navigation constant corresponding to the 2nd page.

                  5. In pages.xml, use:

                  <page view-id="/first-page.jsp">


                  <rule if-outcome="shouldRedirect">
                  <raise-event type="leaveConversation" />
                  <redirect view=id="/secondPage.jsp">





                  6. Define an event listener for leaveConversation event. In the @Observer method for this event, do as follows:

                  i. Conversation.leave().
                  ii. Get conversation entry for the Conversation object and call unlock() on it.

                  This worked perfectly. I know this is not an ideal solution.

                  We would like to suggest that Seam team support ability for specification of a tag like <leave-conversation> in pages.xml (similar to <begin-conversation> and <end-conversation>). That will be the ideal solution to this problem.

                  • 6. Re: how to leave a long running conversation and start a new
                    marcelkolsteren

                    Thanks for presenting your solution to a similar problem. We share the hope for attention of the Seam team to these conversation switching issues. In your case, the new conversation only starts after the redirect, in the next request. That makes a big difference. I need to switch to another conversation inside an action method, and I would like the new conversation to be active in the render response phase, without redirecting. So the ideal solution that you present won't help me out.

                    • 7. Re: how to leave a long running conversation and start a new
                      dgsmith2

                      Marcel, now that it has been a solid 4 years since your post your blog link is no longer up to date.  Any chance you have your solution posted somewhere else?

                      • 8. Re: how to leave a long running conversation and start a new
                        dgsmith2

                        A "solution" we came up with was to use a redirect call within the action method.  I don't know if we will encounter any issues in regards to moving on before Seam may or may not have had opportunity to complete any of its tasks (e.g., flushing contexts, etc)

                         

                        FacesManager.instance().redirect