1 Reply Latest reply on Jun 16, 2009 5:33 PM by Richard Ogin

    How to return to a parent conversation that's also using a pageflow

    Richard Ogin Newbie

      How can I get a nested conversation (that's using a pageflow) to return to a parent conversation (that's also using a pageflow)?

        • 1. Re: How to return to a parent conversation that's also using a pageflow
          Richard Ogin Newbie

          I have a solution, but I'd like help to find out the 'correct way'.


          Here's my example.


          1. Start pageflow of main conversation.


          2. Click link to create nested conversation using specified pageflow.


          Slightly off topic: AFAICT, you cannot create a nested conversation from a s:link that ties to a pageflow, so I made a simple function to do so.


          @Name("...")
          @Scope(ScopeType.STATELESS)
          public class XYZ implements Serializable
          {
               public void nest(String pageflow)
               {
                    Conversation c = Conversation.instance();
                    c.begin(false, true); //may wanna check/notify if this returns false...
                    c.changeFlushMode(FlushModeType.MANUAL); //you don't have to do this, could pass it in, whatever
                    Pageflow p = Pageflow.instance();
                    p.begin(pageflow);
               }
          }
          


          3. Finish your work in the nested process, end the conversation and return to parent.


          This is where I feel a bit dirty, like I'm doing it wrong, but it's the only solution I've found that works without giving an 'illegal navigation' on redirect.


          In the pageflow of the nested conversation, I have the final transitions point to an 'end' decision.


          <decision name="end" expression="#{conversation.endAndRedirect(true)}">
               <transition name="true" to="fake-page"/>
               <transition name="false" to="fake-page"/> --I doubt we wanna continue if the redirect failed, but...
          </decision>
               
          <page name="fake-page" view-id="/i-dont-exist.xhtml"/>
          


          Two things to note.


          1. If you fail to end the conversation before the redirect (the reason we're passing true to endAndRedirect()), you will actually navigate to 'fake-page'.


          2. It is missing logic to check if the conversation is even nested. The logic could be put in a decision node before 'end'. Perhaps better yet, you could write a bean to encapsulate the logic (isNested(), end(), endAndRedirect(true), etc) and just call it on a decision node.


          I hope this helps others who are stuck in a similar situation. If you know a cleaner way to do this, please lemme know!