15.3. Web Flow Configuration

In Web Flow 1 there were two options available for configuring Web Flow, one using standard spring bean XML and the other using the webflow-config-1.0 schema. The schema configuration option simplifies the configuration process by keeping long internal class names hidden and enabling contextual auto-complete. The schema configuration option is the only way to configure Web Flow 2.

Web Flow Bean Configuration

The FactoryBean bean XML configuration method used in Web Flow 1 is no longer supported. The schema configuration method should be used instead. In particular beans defining FlowExecutorFactoryBean and XmlFlowRegistryFactoryBean should be updated. Continue reading Web Flow Schema Configuration for details.

Web Flow Schema Configuration

The webflow-config configuration schema has also changed slightly from version 1 to 2. The simplest way to update your application is modify the version of the schema to 2.0 then fix any errors in a schema aware XML editor. The most common change is add 'flow-' to the beginning of the elements defined by the schema.

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:webflow="http://www.springframework.org/schema/webflow-config"
       xsi:schemaLocation="
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/webflow-config
           http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
			

flow-executor

The flow executor is the core Web Flow configuration element. This element replaces previous FlowExecutorFactoryBean bean definitions.

<webflow:flow-executor id="flowExecutor" />
				

flow-execution-listeners

Flow execution listeners are also defined in the flow executor. Listeners are defined using standard bean definitions and added by reference.

<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
    <webflow:flow-execution-listeners>
        <webflow:listener ref="securityFlowExecutionListener"/>
    </webflow:flow-execution-listeners>
</webflow:flow-executor>

<bean id="securityFlowExecutionListener"
      class="org.springframework.webflow.security.SecurityFlowExecutionListener" />
				

flow-registry

The flow-registry contains a set of flow-locations. Every flow definition used by Web Flow must be added to the registry. This element replaces previous XmlFlowRegistryFactoryBean bean definitions.

<webflow:flow-registry id="flowRegistry">
    <webflow:flow-location path="/WEB-INF/hotels/booking/booking.xml" />
</webflow:flow-registry>
				

Flow Controller

The package name for flow controllers has changed from org.springframework.webflow.executor.mvc.FlowController and is now org.springframework.webflow.mvc.servlet.FlowController for Servlet MVC requests. The portlet flow controller org.springframework.webflow.executor.mvc.PortletFlowController has been replaced by a flow handler adapter available at org.springframework.webflow.mvc.portlet.FlowHandlerAdapter. They will need to be updated in the bean definitions.

Flow URL Handler

The default URL handler has changed in Web Flow 2. The flow identifier is now derived from the URL rather then passed explicitly. In order to maintain comparability with existing views and URL structures a WebFlow1FlowUrlHandler is available.

<bean name="/pos.htm" class="org.springframework.webflow.mvc.servlet.FlowController">
    <property name="flowExecutor" ref="flowExecutor" />
    <property name="flowUrlHandler">
        <bean class="org.springframework.webflow.context.servlet.WebFlow1FlowUrlHandler" />
    </property>
</bean>
			

View Resolution

Web Flow 2 by default will both select and render views. View were previously selected by Web Flow 1 and then rendered by an external view resolver.

In order for version 1 flows to work in Web Flow 2 the default view resolver must be overridden. A common use case is to use Apache Tiles for view resolution. The following configuration will replace the default view resolver with a Tiles view resolver. The tilesViewResolver in this example can be replaced with any other view resolver.

<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
	<web:flow-location path="..." />
    ...
</webflow:flow-registry>

<webflow:flow-builder-services id="flowBuilderServices" 
                               view-factory-creator="viewFactoryCreator"/>

<bean id="viewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    <property name="viewResolvers" ref="tilesViewResolver" />
</bean>

<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles.TilesJstlView" />
</bean>

<bean class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
    <property name="definitions" value="/WEB-INF/tiles-def.xml" />
</bean>