5 Replies Latest reply on Apr 25, 2008 2:21 PM by pmuir

    can't restore parent conversation without redirect

    koatto

      after invoking an action method marked with @End within a nested conversation the parent one is not restored.
      Forcing the  action method to redirect even to the same page with the beforeRedirect attribute, the stuff works.
      that's the use case:


      page :


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
           xmlns:s="http://jboss.com/products/seam/taglib"
           xmlns:ui="http://java.sun.com/jsf/facelets"
           xmlns:f="http://java.sun.com/jsf/core"
           xmlns:h="http://java.sun.com/jsf/html"
           xmlns:c="http://java.sun.com/jstl/core"
           xmlns:a4j="http://richfaces.org/a4j"
           xmlns:rich="http://richfaces.org/rich" >
           <HEAD>
           <title>test </title>
           </HEAD>
      
           <body>
                <h1>test started at : #{currentTime}</h1>
                
                     <h:form >
                          <h:outputText value=" #{currentTime} - id=#{conversation.id} - longRunning=#{conversation.longRunning} - nested=#{conversation.nested}"/>
                          
                          <br/>
                          <h:commandLink ajaxRendered="false" rendered="#{!conversation.longRunning}"  value="start long running"  action="#{convTest.startLongRunning}" >
                                    <s:conversationId/>
                          </h:commandLink>
                          <br/>
                          <h:commandLink  ajaxRendered="false" rendered="#{conversation.longRunning}"  value="end current"  action="#{convTest.endCurrent}">
                                    <s:conversationId/>
                          </h:commandLink>
                          <br/>
                          <h:commandLink   rendered="#{!conversation.nested and conversation.longRunning}"  value="start nested"  action="#{convTest.startNested}">
                                    <s:conversationId/>
                          </h:commandLink>
                     </h:form>
      
           </body>
           
      </html>



      component :



      @Name("convTest")
      public class ConvTest {
           @Logger Log log;
           
           @Begin
           public void startLongRunning(){
                log.debug("startLongRunning");
           }
           @Begin(nested=true)
           public void startNested(){
                log.debug("startNested");
           }
           @End
           public void endCurrent(){
                log.debug("endCurrent");
      
           }
           
      }



      changing the end method in the following way makes everythig work :


      @End(beforeRedirect=true)
           public String endCurrent(){
                log.debug("endCurrent");
                return "/test.xhtml";
           }



      what's wrong?


      Thanks

        • 1. Re: can't restore parent conversation without redirect

          Conversations by default are propagated across a redirect.  Ending a conversation simply demotes the conversation to temporary meaning it will, by default, be carried across the redirect.  By setting beforeRedirect to true, you are telling Seam to demote the conversation temporary and not to propagate the now temporary conversation across the redirect.  In your case with this setting the parent conversation would be active after the redirect occurs since, when using nested conversations, an @End pops the conversation stack resuming the parent.


          Hope that helps.

          • 2. Re: can't restore parent conversation without redirect
            koatto

            i submit my real world use-case in order to let you know what's the problem i'm facing with.


            when the user clicks a certain button a listener annotated with


            @Begin(nested=true)



            is invoked and a component's instance is injected in the newly create conversation context.


            The following pages then check whether or not that instance is null  to conditionally render portions of the UI.
            The nested conversation ends when the user clicks a button invoking an action marked with


            @End



            after the end method has been called the nested conv get demoted to a not longrunning one but my object's instance is still there causing a not correct page rendering.


            What i'd expected was that after the click the parent conversation context was restored and the nested one completely disappeared.


            What i'm i missimg?



            • 3. Re: can't restore parent conversation without redirect
              pmuir

              Jacob explained the theory correctly - simply that the conversation is still there, but just temporary. So, use beforeRedirect=true
              if you need the behaviour you describe.

              • 4. Re: can't restore parent conversation without redirect
                koatto

                even if the request is going to trigger the rendering of the same page? In my specific case that ending method is addressed by an ajax request.


                Thanks.

                • 5. Re: can't restore parent conversation without redirect
                  pmuir

                  No, you need to do a redirect, even if it is back to the same page. There is no way to get a totally new conversation on just a render.