6 Replies Latest reply on Aug 1, 2008 10:24 PM by luxspes

    Declaratively end any levels of nested conversations

      Hi!


      Lets say I am inside 4 levels of nested Conversation, and I have 1 action that, after executing has to end the current nested conversation and redirect me to a particular page. This is easy, I just:


      <navigation from-action="#{bienMuebleHomeC.remove}">
               <rule>
              <end-conversation/>
              <redirect view-id="/Inventario/BienMuebleFromC.xhtml"/>
             </rule>
         </navigation>
      



      Now lets say tha, if certain query parameters are configured in a particular way it should end all nested conversations and the parent long-running conversation and redirect me to another page:


      <navigation from-action="#{bienMuebleHomeC.remove}">
                 <rule>
              <end-conversation if ="#{empty bienMuebleFrom}"/>
              <end-all-nested-and-main-long-conversation if ="#{not empty bienMuebleFrom}"/>
              <redirect view-id="/Inventario/#{empty bienMuebleFrom ? 'BienMuebleListC' : bienMuebleFrom}.xhtml"/>
             </rule>
         </navigation>
      



      Of course, my problem that <end-all-nested-and-main-long-conversation> does not exist (in fact, I am not sure that is good name for it, it could be a better idea to have something like:



      <navigation from-action="#{bienMuebleHomeC.remove}">
                 <rule>
              <end-conversation if ="#{empty bienMuebleFrom}"/>
              <end-conversation levels="*" if ="#{not empty bienMuebleFrom}"/>
              <redirect view-id="/Inventario/#{empty bienMuebleFrom ? 'BienMuebleListC' : bienMuebleFrom}.xhtml"/>
             </rule>
         </navigation>
      



      With something like <end-conversation levels="*"> it could even be possible to control how many levels of nested conversations are closed.


      Am I right to think that this would be a nice feature to have? (Or is there another better already available way to deal with this in a declarative way?)


      Thanks,


      Regards,









        • 1. Re: Declaratively end any levels of nested conversations
          pmuir
          • 2. Re: Declaratively end any levels of nested conversations

            Hi!


            I wasn't sure if I should post this on JIRA or here, so I posted it in both (if that is wrong just tell me and I will not happen again):


            Is @End(root=true) the most flexible way to deal with this problem? what if one need to end only 2 or 3 levels of nested conversations, wouldn't it be better if had an option like:


            @End(levels="#{3}")



            to end all nested conversation (but not root) (regardless of the nesting levels) something like


            @End(levels="#{conversation.nestingLevel}")



            and, to end the root conversation (regardless of the nesting levels) something like


            @End(levels="#{conversation.nestingLevel+1}")



            Of course that means we would need to add the nestingLevel to conversation.


            Regards,


            • 3. Re: Declaratively end any levels of nested conversations

              And same thing for .pages.xml:


              <navigation from-action="#{bienMuebleHomeC.remove}">
                    <rule if="#{not empty bienMuebleFrom}">
                         <end-conversation levels="#{conversation.nestingLevel+1}"/>
                         <redirect view-id="/Inventario/#{empty bienMuebleFrom ? 'BienMuebleListC' : bienMuebleFrom}.xhtml"/>
                     </rule>              
                 </navigation>
              



              What do you think?

              • 4. Re: Declaratively end any levels of nested conversations

                Hi!


                I do not think JBSEAM-1943 is the solution to my problem, because I do not need to end the root conversation, I need to end all nested conversations but keep the root one, at first, I thought that this would work:


                private void endRootConversation() {
                Conversation conversation = Conversation.instance();
                
                while(conversation.isNested()) {
                conversation.root();
                }
                
                conversation.endBeforeRedirect();
                }
                



                but it obviusly doesnt (as it ends the root of all nested conversations).


                So, since for now I only need to end 2 levels, I tried with:


                private void endRootConversation() {
                 Conversation conversation1 = Conversation.instance();
                 conversation.end();
                 Conversation conversation2 = Conversation.instance();
                 conversation.end();
                }
                



                But it doesn't seem to be working (it seems to be ending only one level of nested conversations).


                Any hints on how could I end 2 levels? (or simply all nested ones but not the initial long running one?)


                Thanks,


                Regards,

                • 5. Re: Declaratively end any levels of nested conversations

                  I am sorry, my second example should have been:



                  private void endNestedConversations() {
                   Conversation conversation1 = Conversation.instance();
                   conversation1.end();
                   Conversation conversation2 = Conversation.instance();
                   conversation2.end();
                  }
                  



                  Thanks,

                  • 6. Re: Declaratively end any levels of nested conversations

                    Finally found the way:


                          @Override
                          public String remove() {
                               String remove = super.remove();
                            switchToParentConversation();
                            return remove;
                          }
                    
                          private void switchToParentConversation() {          
                               Conversation conversation1 = Conversation.instance();
                            Manager.instance().switchConversation(conversation1.getParentId());
                          }
                    



                    after that, the .page.xml ends the right conversation:


                         <navigation from-action="#{someEntityHome.remove}">
                              <rule>
                                   <end-conversation />
                                   <redirect
                                        view-id="someViewId.xhml" />
                              </rule>
                         </navigation>
                    



                    I still feel that this should be solved declaratively with:


                    <end-conversation levels="conversation.nestingLevel"/>
                    



                    Regards,