(From SpringSource forum.)
When the HttpSession
has expired and the user re-submits a page in the flow, he/she is sent back to the beginning of the flow. All I want to add to this behavior is a message explaining why it occurred. "You were inactive, so you have been restarted..."
What's the easiest/best-practice way to do this?
From the Jira request I had opened, WebFlow developer says,
I haven't been able to confirm, but wanted to share the information.
The default behavior, in FlowHandlerAdapter.defaultHandleException(), "attempts to start a new execution of the ended or expired flow".
It looks like a WebFlow way to handle this would be to provide a
FlowHandler
with a handleException() method that checks for aninstanceof NoSuchFlowExecutionException
, then do something like construct a redirect URL or place something on Session scope that can later be removed once utilized.Due to the way WebFlow uses redirects, I don't think any other scopes would allow such a flag or message to be used later when the new flow's view renders.
However, simply detecting a new Session in an
Interceptor
or even aFilter
would seem to be just as effective. Which is what I ended up doing in my previous investigation of this, as documented in the referenced forum thread. I was just hoping for something prettier.Also, by the time the new flow begins, a new Session ID has already been created, so there's no way to initially detect this condition from within the flow.xml.
Sample filter logic:
Sample Interceptor:
Step 1: FlowController has a default handlerAdapter. To customize session exceptions you are required to write your own custom handler adapter and register it with the flow controller bean as below:
Step 2: CustomFlowHandlerAdapter In this class override defaultHandleException method. this is the method that webflow invokes in case of exceptions and re-initializes session. please note, new session has already been created till this point. Only the exception type will tell you at this point that the previous session timed out.
The first view page of your app should be able to show this message.
Hope this helps.