Spring MVC with Spring Webflow
I am trying to use Spring Webflow with my Spring MVC application. I looked at the booking-mvc example and followed, but most of the examples on the web are made with Tiles.I Hope I'm not completely wrong in my understanding and that Spring Webflow can be used with Spring MVC
I am trying to use Spring MVC controllers. But when I do a transition like submit / finish, nothing happens.
Here is my xml stream:
<view-state id="enterBookingDetails">
<transition on="submit" to="reviewBooking" />
</view-state>
<view-state id="reviewBooking">
<transition on="confirm" to="bookingConfirmed" />
<transition on="revise" to="enterBookingDetails" />
<transition on="cancel" to="bookingCancelled" />
</view-state>
I have enterBookingDetails and reviewBooking defined as controllers:
@RequestMapping(value = "/enterBookingDetails", method = RequestMethod.GET)
public ModelAndView getPage(final HttpServletRequest request) {
ModelAndView modelView = new ModelAndView();
modelView.setViewName("pa");
return modelView;
}
@RequestMapping(value = "/reviewBooking", method = RequestMethod.GET)
public ModelAndView getPage2(final HttpServletRequest request) {
ModelAndView modelView = new ModelAndView();
modelView.setViewName("pb");
return modelView;
}
My Jsp looks like this:
<form:form>
<input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}" />
<input type="hidden" name="_eventId" value="finished" />
<input type="submit" value="Submit" name="_eventId_finished" />
</form:form>
And finally my config:
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="mvcViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="order" value="1" />
</bean>
<!-- Register all Web Flow definitions under /WEB-INF/flows/**/*-flow.xml -->
<webflow:flow-registry id="flowRegistry"
base-path="/WEB-INF/flows" flow-builder-services="flowBuilderServices">
<webflow:flow-location-pattern value="/**/*-flow.xml" />
</webflow:flow-registry>
<!-- Deploy a flow executor -->
<webflow:flow-executor id="flowExecutor" />
<!-- Configure flow builder services -->
<!-- Configure view service -->
<webflow:flow-builder-services id="flowBuilderServices"
view-factory-creator="mvcViewFactoryCreator" />
<!-- Web Flow components -->
<!-- Install flow handler (FlowHandlerAdapter) -->
<!-- It dispatches URL requests to flows -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
<!-- Map Http request path to flows register in the registry -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry" />
<property name="order" value="0" />
</bean>
<bean id="mvcViewFactoryCreator"
class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="mvcViewResolver"/>
</bean>
source to share
Spring Webflow is built on spring web mvc, so the two can be used together.
I found out that the problem with this combination is that when something is misconfigured the only symptom is "nothing happens". I ended up looking at the debug logs for org.springframework.web and org.springframework.webflow and then tracing back to spring source code to diagnose configuration issues.
The spring paradigm focuses on "convention over configuration". The problem I am facing is that conventions are not always well defined in a way that someone already familiar with them can easily understand.
The last "gotcha" I had to solve is that the convention for spring webflow is to put the XML stream files in the same folder as the jsp.
In your example, you are planning to switch between spring-webflow and unadorned web mvc behind the same view. Assuming everything is set up correctly, for a given uri, anything in the webflow registry will trump anything in the UrlHandlerMapping (your annotations). This can be confusing if you are not aware of it.
source to share