Grails webflow - Swapping Webflows in the same session
I have a Grails application with two webflows:
One for Purchasing
Another for getting in Contact with us
The issue:
It can happen that a user has a number of steps taken in a purchase wizard
(via a webflow), he/she then decides they have a question and try to
contact us (also via a webflow). So the user clicks on the 'contact-us'
link on our navigation menu but they get brought back to the last step
they were on in the purchase flow. Personally I assume it's got to do with
the 'execution' key in the session which every link gets postfixed with
i.e.
...../contact_us/index?execution=e1s1
The solution I would like:
I would like (in the above case), if the user decides himself to swap from
the 'purchase flow' to the 'contact-us flow' that the 'purchase flow' gets
invalidated/removed and the user begins from scratch in the 'contact-us
flow'.
Grails version 2.2.3 Webflow plugin: 2.0.8.1
The best solution I could come up with (without doing something too ugly)
was to create a filter that intercepts when a link has been clicked to
start a new flow and attempts to remove the other one. However, in this
example it surprisingly fails to find the flow in the flow repository
(nullpointer).
FlowExecutionLock flowExecutionLock = null;
SessionBindingConversationManager conversationManager =
applicationContext.getBean('conversationManager');
DefaultFlowExecutionRepository flowExecutionRepository =
applicationContext.getBean("flowExecutionRepository");
try {
// executionKey is something like 'e1s1'
FlowExecutionKey flowExecutionKey =
flowExecutionRepository.parseFlowExecutionKey(executionKey);
flowExecutionLock = flowExecutionRepository.getLock(flowExecutionKey);
flowExecutionLock.lock();
FlowExecution execution =
flowExecutionRepository.getFlowExecution(flowExecutionKey);
flowExecutionRepository.removeFlowExecution(execution);
} catch (FlowExecutionRepositoryException e) {
log.warn("Could not find flow in repository with id ${executionKey} "
+ e.getMessage());
} catch (NullPointerException e) {
log.warn("Could not find flow in repository with id ${executionKey} "
+ e.getMessage());
} finally {
if (flowExecutionLock != null) {
flowExecutionLock.unlock();
}
}
Has anybody got any ideas how I could do this. Swapping between two flows
(where one is incomplete) in a session should be possible right? I'd like
a clean solution to this rather than tweaking the flows themselves.
No comments:
Post a Comment