Expert Spring MVC and Web Flow

(Dana P.) #1

Continuations


Continuations (http://www-128.ibm.com/developerworks/java/library/j-contin.html,
http://en.wikipedia.org/wiki/Continuation) allow you to capture the entire state of a system
at a point in time and isolate that state in a form that can be resumed at a later point. They
effectively allow you to go back in time and restore a system as it was at that time, “continu-
ing” from there.

■Tip Remember, Spring Web Flow already has an object that represents the execution of a flow at a
specific point in time, the FlowExecution.

The Problem of Back Buttons and New Browser Windows
You’ll see that a continuation-based approach is a powerful concept that, when applied to the
domain of web applications, helps solve many problems that plague web developers, includ-
ing the well-known Back button problem.
Recall in Spring Web Flow that the state of a user conversation at a point in time is held
by a FlowExecutionobject, which is stored in a repository between requests. The source of a
repository is configurable, and Spring Web Flow provides both server-side and client-side
solutions. If the repository is stored server-side in the user’s session and there is only a single
copy of a FlowExecutionper user conversation, the following issues start to arise:


  • What if during the conversation the user goes back in his local history without telling
    the server? The browser is now “out of sync” with the state of the FlowExecutionon the
    server. This could result in signaling an event in the wrong state or even the wrong flow
    (when using subflows).

  • What if the user launches a new window? Both windows will reference the same
    FlowExecution. Doing work in either window will cause problems, as the other window
    will then be out of sync with the server.


Clearly, a trivial form of FlowExecutionstorage is not good enough when browser naviga-
tional button support is a requirement. Continuations provide a good solution to this
problem.
With a continuation-based approach, instead of storing a single copy of a FlowExecution
for a logical conversation, you store multiple copies, where each copy represents the state of
the conversation at a point in time that is restorable. Given this, consider the case of going
back within local browser history. When you click Back, you go back to a page that references a
specific FlowExecutionContinuation, which represents a restorable snapshot of the conversa-
tion at that time. When you click a submit button, the FlowExecutionis restored at that point
and continued from there. It is always restored in the correct state, so the client always
remains in sync with the server.

354 CHAPTER 12 ■ADVANCED SPRING WEB FLOW

Free download pdf