2 Replies Latest reply on Feb 1, 2009 8:44 AM by Naresh Bhatia

    Seam lifecycle and redirects

    Naresh Bhatia Newbie

      I have a question about the Seam lifecycle: when exactly is the conversation context ended and destroyed in case of a redirect?


      I have the following situation where the openaccount page redirects to an accounts page:


      <page view-id="/openaccount.xhtml">
      
          <begin-conversation join="true" />
      
          <navigation from-action="#{openAccountController.openAccount}">
              <rule if-outcome="loggedIn">
                  <end-conversation/>
                  <redirect view-id="/accounts.xhtml" />
              </rule>
          </navigation>
      
      </page>
      



      Here's a log of activities during the Seam lifecycle:


      [org.jboss.seam.contexts.FacesLifecycle] >>> Begin JSF request for /myapp/openaccount.seam
      [samples.util.jsf.TracingPhaseListener] >>> Entering JSF phase RESTORE_VIEW 1
      [samples.util.jsf.TracingPhaseListener] <<< Exiting JSF phase RESTORE_VIEW 1
      [samples.util.jsf.TracingPhaseListener] >>> Entering JSF phase APPLY_REQUEST_VALUES 2
      [samples.util.jsf.TracingPhaseListener] <<< Exiting JSF phase APPLY_REQUEST_VALUES 2
      [samples.util.jsf.TracingPhaseListener] >>> Entering JSF phase PROCESS_VALIDATIONS 3
      [samples.util.jsf.TracingPhaseListener] <<< Exiting JSF phase PROCESS_VALIDATIONS 3
      [samples.util.jsf.TracingPhaseListener] >>> Entering JSF phase UPDATE_MODEL_VALUES 4
      [samples.util.jsf.TracingPhaseListener] <<< Exiting JSF phase UPDATE_MODEL_VALUES 4
      [samples.util.jsf.TracingPhaseListener] >>> Entering JSF phase INVOKE_APPLICATION 5
      [samples.myapp.util.TraceInterceptor] >>> Entering method 'openAccount'
      [samples.myapp.util.TraceInterceptor] <<< Exiting method 'openAccount'
      [samples.util.jsf.TracingPhaseListener] <<< Exiting JSF phase INVOKE_APPLICATION 5
      [org.jboss.seam.contexts.FacesLifecycle] After render response, destroying contexts
      [org.jboss.seam.contexts.FacesLifecycle] <<< End JSF request for /myapp/openaccount.seam
      [org.jboss.seam.contexts.FacesLifecycle] >>> Begin JSF request for /myapp/accounts.seam
      [samples.util.jsf.TracingPhaseListener] >>> Entering JSF phase RESTORE_VIEW 1
      [samples.util.jsf.TracingPhaseListener] <<< Exiting JSF phase RESTORE_VIEW 1
      [samples.util.jsf.TracingPhaseListener] >>> Entering JSF phase RENDER_RESPONSE 6
      [samples.util.jsf.TracingPhaseListener] <<< Exiting JSF phase RENDER_RESPONSE 6
      [org.jboss.seam.contexts.FacesLifecycle] After render response, destroying contexts
      [samples.myapp.web.util.SeamEventTracer] >>> Start destroying conversation context
      [samples.myapp.web.util.SeamEventTracer] <<< Done destroying conversation context
      [org.jboss.seam.contexts.FacesLifecycle] <<< End JSF request for /myapp/accounts.seam
      



      Here's how I am interpreting the log:



      • JSF lifecycle for openaccount begins

      • During the INVOKE APPLICATION phase the action method openAccount() is called

      • After the action method returns, there is a redirect which causes the RENDER RESPONSE phase to be skipped and the JSF lifecycle for the openaccount page ends. At this point, I can't tell if the conversation has been ended (i.e. demoted to temporary) in spite of the end conversation directive.

      • The next step is a fresh JSF lifecycle for the redirected page, which goes though the RESTORE VIEW and RENDER RESPONSE phases

      • At this point the conversation is destroyed and the JSF lifecycle for the redirected page ends.



      Given this, my questions are:



      1. Does Seam end the conversation before the redirect (i.e. demote it to temporary)?

      2. Is the conversation context destroyed only after the redirect?

      3. Would the behavior be any different if the conversation was temporary and not long-running?

      4. Is there a better way to trace the Seam lifecycle? I am essentially logging org.jboss.seam.contexts.FacesLifecycle and also observing preDestroyContext and postDestroyContext events on conversations. This is still not giving me enough information on when the conversation is created, when it is changed from temporary to long-running etc.



      I would really appreciate your help on getting the basics out of my way. I have read the Seam reference as well as the Seam in Action book, but some of these concepts are still a little fuzzy.


      Naresh

        • 1. Re: Seam lifecycle and redirects
          alberto Gori Novice


          Does Seam end the conversation before the redirect (i.e. demote it to temporary)?


          By default Seam end conversation after redirect. If you want ending it before redirect you can just use


          <end-conversation before-redirect="true"/>
          



          The before-redirect feature is available also by annotations and Seam conversation API.




          Would the behavior be any different if the conversation was temporary and not long-running?


          I don't think a temporary conversation is different from this point of view.




          Is there a better way to trace the Seam lifecycle?


          I don't know...

          • 2. Re: Seam lifecycle and redirects
            Naresh Bhatia Newbie

            Thanks Alberto, your answer does clarify my question. I hope future versions of Seam will have better logging of the Seam lifecycle.