Seam lifecycle and redirects
nbhatia.bhatian.comcast.net Jan 31, 2009 3:25 PMI 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:
- Does Seam end the conversation before the redirect (i.e. demote it to temporary)?
- Is the conversation context destroyed only after the redirect?
- Would the behavior be any different if the conversation was temporary and not long-running?
- 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