5 Replies Latest reply on Apr 22, 2007 9:43 AM by Vladimir Ralev

    Ending multiple nested conversations?

    anti spart Newbie

      I'd like a call to endNested1() to kill all 3 nested conversations if the if() statement evaluates to true for all 3 methods.

      What I find is happening though is that only the most nested (deepest) conversation gets killed even though Conversation.instance().end(); is being called 3 times.

      Is there a way to make this work?

      public void endNested1() {
       endNested2();
      
       if ()
       Conversation.instance().end();
      }
      
      public void endNested2() {
       endNested3();
       if ()
       Conversation.instance().end();
      }
      
      public void endNested3() {
       Conversation.instance().end();
      }


        • 1. Re: Ending multiple nested conversations?
          anti spart Newbie

          It looks like this may be what I want (?)

          if (...) {
           Conversation.instance().end();
           Conversation.instance().leave();
          }


          • 2. Re: Ending multiple nested conversations?
            Gavin King Master

            No, but you can add a feature request to JIRA if you like.

            • 4. Re: Ending multiple nested conversations?
              Vladimir Ralev Newbie

              Here is my solution:

              Add this method to org.jboss.seam.core.Manager

               /**
               * End a conversation together with all nested conversations. The
               * conversation passed in cid will be destroyed at the end of the
               * request while the nested conversations are destroyed immediately.
               *
               * @param cid the ID of the conversation
               */
               public void endConversationByID(String cid, boolean beforeRedirect)
               {
               log.debug("Ending long-running conversation");
              
               if ( Events.exists() ) Events.instance().raiseEvent("org.jboss.seam.endConversation");
              
               ConversationEntries ce = (ConversationEntries)
               Component.getInstance("org.jboss.seam.core.conversationEntries");
               setCurrentConversationId( cid );
               setCurrentConversationIdStack(
               ce.getConversationEntry( cid ).getConversationIdStack());
               setLongRunningConversation( false );
               destroyBeforeRedirect = beforeRedirect;
               endNestedConversations( cid );
               storeConversationToViewRootIfNecessary();
               }
              


              In the bean do this:

               public String endParent()
               {
               Manager m = (Manager)Component.getInstance("org.jboss.seam.core.manager");
               m.endConversationByID(Conversation.instance().getParentId(), false);
               return "next.seam";
               }
              
               //Assuming conversations 1->2->3
               public String endParentOfParent()
               {
               Manager m = (Manager)Component.getInstance("org.jboss.seam.core.manager");
              
               // kill immediately 3, set Conversation.instance() to 2 and mark it to
               // be ended at the end of the request
               m.endConversationByID(Conversation.instance().getParentId(), false);
              
               // kill immediately 2, set Conversation.instance() to 1 and mark it to
               // be ended at the end of the request
               m.endConversationByID(Conversation.instance().getParentId(), false);
               return "next.seam";
               }
              


              The endParent() kills the current conversation immediately and the parent at the end of the request. If you want to kill the parent of the parent too, you can call endConversationByID against Conversation.instance().getParentId() because the current Conversation instance is actually the conversation scheduled to be destroyed at the end of the request.


              • 5. Re: Ending multiple nested conversations?
                Vladimir Ralev Newbie

                Actually it's better to use the instance methods

                 /**
                 * End a conversation together with all nested conversations. The
                 * conversation passed in cid will be destroyed at the end of the
                 * request while the nested conversations are destroyed immediately.
                 *
                 * @param cid the ID of the conversation
                 */
                 public void endConversationByID(String cid, boolean beforeRedirect)
                 {
                 log.debug("Ending long-running conversation");
                
                 if ( Events.exists() ) Events.instance().raiseEvent("org.jboss.seam.endConversation");
                
                 ConversationEntries ce = ConversationEntries.instance();
                 setCurrentConversationId( cid );
                 setCurrentConversationIdStack(
                 ce.getConversationEntry( cid ).getConversationIdStack());
                 setLongRunningConversation( false );
                 destroyBeforeRedirect = beforeRedirect;
                 endNestedConversations( cid );
                 storeConversationToViewRootIfNecessary();
                 }
                


                with

                 public String endParent()
                 {
                 Manager m = Manager.instance();
                 m.endConversationByID(Conversation.instance().getParentId(), false);
                 return "next.seam";
                 }
                
                 //Assuming conversations 1->2->3
                 public String endParentOfParent()
                 {
                 Manager m = Manager.instance()
                
                 // kill immediately 3, set Conversation.instance() to 2 and mark it to
                 // be ended at the end of the request
                 m.endConversationByID(Conversation.instance().getParentId(), false);
                
                 // kill immediately 2, set Conversation.instance() to 1 and mark it to
                 // be ended at the end of the request
                 m.endConversationByID(Conversation.instance().getParentId(), false);
                 return "next.seam";
                 }