Spring WebFlow config

Basic configuration for Web Flow:

    <!-- WebFlow configuration -->
    <flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"  />

    <flow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
        <flow:flow-location id="flow"
            path="/WEB-INF/spring/flow/web-flow.xml" />
    </flow:flow-registry>

    <beans:bean
        class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"
        p:flowRegistry-ref="flowRegistry" />

    <beans:bean
        class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"
        p:flowExecutor-ref="flowExecutor" />

Then from the flow file (web-flow.xml in this case) just return the view as:

<!-- serve from WEB-INF -->
<view-state id="home"  view="/WEB-INF/views/home.jsp" />

<!-- or serve from web app root -->
<view-state id="home2"  view="/views/home.jsp" />

Note: We can access this flow from: http://<server>/<app>/<flowName >
The flow name will be the id used in the flow registery, “flow” for this example:

Note, attempting to serve an non jsp page with that setup will yield:

java.lang.IllegalArgumentException: Unsupported view type /home only types supported by this FlowViewResolver implementation are [.jsp] and [.jspx]

To resolve we can use the same InternalResourceViewResolver that Spring MVC uses, (Learned solution by reading this thread from Spring forums) :

<!-- Resolves views selected for rendering by @Controllers to .jsp resources 
    in the /WEB-INF/views directory -->
<beans:bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>
<flow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator"/>

 <!-- Use the existing view resolver -->
 <beans:bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
    <beans:property name="viewResolvers" ref="viewResolver"/>
 </beans:bean>

After this we can serve request using logical names just like we would from MVC Controllers 🙂

Advertisements
Posted in Java, Spring, Spring WebFlow
2 comments on “Spring WebFlow config
  1. tony says:

    you did not specify the class for “mvcViewFactoryCreator”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: