Introduction to Spring Web Flow


Spring Web Flow is an extension to Spring MVC, that helps in implementing the flows in a complex web application. It allows us to create logical flows in our web application.

Features of Spring Web Flow:

  1. There is a fixed start and an end point.
  2. The user must navigate in a specific order to run the application.
  3. The changes are finalized only after reaching the last step successfully.
  4. Once complete it shouldn’t be possible to repeat the same transaction again.

The most common scenarios where Spring Web Flows are used, are in Banking and Insurance applications.

How does Spring Web Flow work?

  1. There is always a start state, which helps in creating the initial state of the flow. Note that if the start state is not specified, the first view state becomes the start state.
  2. An action state executes a particular action and based on the result that is returned, the flow moves to the corresponding view state, which awaits user activity before the flow further proceeds.
  3. A decision state is used to check the attribute or property at run-time and directs the flow accordingly.
  4. A sub-flow state represent independent flows from the main flow. When an application enters a sub-flow, the main flow is paused until the concerned sub-flow completes.
  5. There is an end state as well. When the main flow reaches the end state, all the resources associated with it are cleaned up automatically.

Following is a sample Web Flow, over which we will be creating our first Spring Web Flow based web application:

To note:

All the expressions within the <on-start> tag are resolved first before the flow reaches the start state.

validate is an action state, which evaluates the validateDetails method and fires the transition accordingly based on the return value.

The above web flow could be better understood by comparing the below flow diagram with the actual Web Flow XML.

Spring Web Flow

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.