Browse DevX
Sign up for e-mail newsletters from DevX


Spring WebFlow Sneak Preview: Reuse and Framework Abstraction : Page 2

Spring WebFlow is a new Web framework that brings an innovative and highly structured approach to building Web applications. Get a sneak peek of the features in this next-generation Spring offering.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Key Components of WebFlow

A Spring WebFlow application consists of one or more flows, which commonly include ActionStates that execute Actions, ViewStates, and Transitions.

A Flow

A flow is a predefined set of user interactions within a Web application expressed as a tree of action states and view states connected via transitions.

The following login-registration excerpt is an example of a Web flow with some typical components, such as loginForm, ActionState, and transitions. It is expressed in a WebFlow XML document that describes the composition of high-level flow components:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE webflow PUBLIC "-//SPRING//DTD WEBFLOW//EN" "http://www.springframework.org/dtd/spring-webflow.dtd"> <webflow id="LoginSequence" start-state="loginForm"> <action-state id="loginForm"> <action bean="loginFormAction"/> <transition on="success" to="formView"/> </action-state> ... <view-state id="formView" view="enterCredentials"> <transition on="submit" to="bindAndValidateForm"/> </view-state> ... <end-state id="successView" view="displayMain"/>

Flow starts with the initial transition to the action state "loginForm", and it ends with "successView", which renders the view component for the main page "displayMain". Flows can be captured either in an XML document or as Java classes that extend AbstractFlowBuilder.


ActionStates are reactions to user-generated or other events. ActionStates themselves can include executions of one or more executable Actions as well as transitions. In the following snippet, the "loginForm" ActionState consists of an executable action ("loginFormAction") with only one possible transition defined ("success") to "formView":

<action-state id="loginForm"> <action bean="loginFormAction"/> <transition on="success" to="formView"/> </action-state>


Actions are atomic units of behavior that ActionStates can chain together, reuse, and declaratively invoke. Actions are extensions of the AbstractAction object, which implements the method doExecuteAction. This method accepts a RequestContext, a WebFlow object that encapsulates all the pertinent values passed from the flow. The loginForm ActionState invokes a LoginFormAction via Spring's auto-wiring feature. Its doExecuteAction is automatically invoked, and it can perform some login setup operations, pre-population, etc.:

public LoginFormAction extends AbstractAction{ protected Event doExecuteAction(RequestContext context) throws Exception{ //perform some login specific setup operations ... }//end method }//end class


A ViewState initiates the rendering of some kind of a view component, such as jsp, tile, etc. In the following snippet, ViewState is invoked as a "success" transition from a loginForm ActionState. It will render the "enterCredentials" view component, which could be a Struts forward to a jsp or a tile:

<view-state id="formView" view="enterCredentials"> <transition on="submit" to="bindAndValidateForm"/> </view-state>


As in a formal state machine, WebFlow defines states and transitions between states. WebFlow transitions are similar to Struts ActionForwards, and they are responsible for linking from one state to another.


Continuations allow backtracking and re-forking of program execution flows—a trip back in time from the program execution perspective. Continuations, originally a programming language concept, never formally made it into mainstream languages such as Java, VB, or C++. WebFlow implements continuations in a very innovative way. It uses them to allow for free navigation within a Web application, since WebFlow continuations can be used to persist and re-store any flow states.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date