0
votes

I have a Grails application with two webflows:

  1. One for Purchasing
  2. 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

Attempted Solution

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 {
    String executionKey = params.get("execution");// 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();
    }
}

Ideas?

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.

1

1 Answers

0
votes

I seem to have found a workaround, in the g:link tag (where I create the link to the flow) I don't always make the habit of adding the action "index" as in Grails it goes there by default but it seems when I added it, I was able to swap between flows seamlessly.

<g:link absolute="true" controller="contact_us" action="index">

I am not sure if the old flows are removed from the flow repository. I have tried clicking between the two flows 70-80 times and nothing seems to be appearing in the log. If I do get any issues I'll come back and update the answer.