Reuse with WebFlow
The flow definitions in WebFlow, like LoginSequence, are intentionally structured for reuse. They have well defined entry and exist states, and the states and transitions have well encapsulated lifecycles. The definitions are easy to configure and reuse with the Spring-enabled Web components. Architects should recognize and define common flows, such as login sequences, searches, and summary-details displays, and have them defined as reusable flows.
Furthermore, Actions, if architected properly in conjunction with the Spring framework, also are reusable components. They can be made parts of the action states in the multiple flows as well. This reuse, at both the overall Web-application and the flow levels in the action states, helps reduce the overall size of your application and improves its maintainability and understandability.
WebFlow Integration with Struts
WebFlow integrates with Struts out of the box, partly through the standard Spring classes and configurations available in the
package. Integration with WebFlow-specific concepts, such as Actions and ActionFlows, requires only registering the Actions to be executed with WebFlow-specific Struts actions and incorporating them into an ActionFlow.
The following snippet is from struts-config.xml. It illustrates how the Struts Action is configured as an entry point to the flow. Notice the WebFlow-specific type for the Action class (
org.springframework.web.flow.struts.FlowAction), and the property "flowId", which connects the Action to the login sequence flow. The example login sequence is managed as a loginFlow bean in the Spring's ApplicationContext. You would need to register the flow as a Spring-managed bean:
<! flow actions >
<set-property property="flowId" value="loginAction" />
The example also uses the RequestProcessor from the Spring framework, (
org.springframework.web.struts.BindingRequestProcessor) which enables Spring's automatic form-to-bean object binding. This Spring feature prevents a proliferation of individual transient ActionForm objects:
As well, it requires the use of the convenience class, which auto-binds Web form values to Java objects' properties:
The WebFlow pre-release, which is available for immediate download, contains a short and effective sample application ("birthdate") that illustrates all the major points in this integration process. If you are interested in WebFlow, explore this sample application.