Reputation: 9604
I am adding Spring Web Flow 2 to a very large existing web application that does not currently use Spring MVC or Web Flow. My task is to have the Web Flow triggered by going to mySite.com/flows, and I am having difficulties. My approach was to set up the DispatcherServlet with mapping of /flows/*
and map Web Flow to /flows
. Here is my web.xml where the DispatcherServlet is configured:
<servlet>
<servlet-name>flow</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/flowContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>flow</servlet-name>
<url-pattern>/flows/*</url-pattern>
</servlet-mapping>
I have tried several methods to get the Web Flow to map to /flows
. My first try was to use a flow-registry with base-path
setting:
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app/flows">
<webflow:flow-location-pattern value="**/*-flow.xml" />
</webflow:flow-registry>
My understanding is that this will take the folder structure inside of the /WEB-INF/app/flows
to create the request mapping. My first test was to add my flow, booking-flow.xml
inside a subfolder called booking
(/WEB-INF/app/flows/booking
). And, great! - it worked as expected. I was able to access the flow from mySite.com/flows/booking. OK, but I don't want /booking
in the URL, so I moved the booking-flow.xml
out of the booking
folder, and straight into WEB-INF/app/flows
and expected that to work for me, but it did not - I don't think the flow mapped at all.
Does anyone know how I can map a flow to the root of the DispatcherServlet mapping, or is there a better way to approach this? I don't want the DispatcherServlet to handle any requests outside of /flows
in my application. Is it just me, or is there very little documentation available on Spring Web Flow?
Thanks!
Upvotes: 5
Views: 8347
Reputation: 68905
As per your current file structure setup you can either do
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app/flows">
<webflow:flow-location path="booking-flow.xml" id="flows"/>
</webflow:flow-registry>
i.e you give id explicitly in which case URL applicable would be - mySite.com/flows
OR
you can remove flows from base context -
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app">
<webflow:flow-location-pattern value="**/*-flow.xml" />
</webflow:flow-registry>
and out your file in /WEB-INF/app/flows/booking-flow.xml
. This will automatically generate id corresponding to path between base path and your file name - which will be flows
and again URL applicable will be mySite.com/flows
Upvotes: 0
Reputation: 127
Another way could be like this
<!-- Registry of executable flows -->
<flow:flow-registry flow-builder-services="flowBuilderServices"
id="flowRegistry" base-path="/WEB-INF/flows/">
<flow:flow-location id="hello" path="hello-flow.xml" />
<flow:flow-location path="start-flow.xml" id="main" />
</flow:flow-registry>
invoke flows using the id's like hello.htm or hello.html depending upon the url mapping.first view state in the respective file will be loaded.
Upvotes: 1
Reputation: 362
You can use SimpleUrlHandlerMapping this way to map your flow to mySite.com/flows
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings" value="flows=flowController" />
</bean>
<bean id="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
</webflow:flow-executor>
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/app/flows">
<webflow:flow-location path="booking-flow.xml" id="flows"/>
</webflow:flow-registry>
Upvotes: 5