Question

I am putting together a simple Spring MVC with Web Flow app and I cannot get it to render the flowExecutionUrl on a page so that I can navigate to the next state. Which I assume means the flow isn't starting(is there an explicit trigger?). I'm assuming there is something wrong in my setup, although the logs suggest I am registering the flow.xml file correctly.

My spring config(mvc-dispatcher-servlet.xml) is:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-3.1.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd">
<context:component-scan base-package="com.intl.cigna.ecommerce.controller" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/WEB-INF/view/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
<mvc:annotation-driven/>

<!-- Forwards requests to the "/" resource to the "welcome" view -->
<mvc:view-controller path="/" view-name="welcome"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
  <property name="persistenceUnitName" value="com.intl.cigna"/>

<!-- Configures Handler Interceptors -->   
<mvc:interceptors>
    <!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>

<!-- Saves a locale change using a cookie -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />

<!-- Application Message Bundle -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="/WEB-INF/messages/messages" />
    <property name="cacheSeconds" value="0" />
</bean>

<!-- Enables FlowHandler URL mapping -->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
</bean>
<webflow:flow-executor id="flowExecutor" />
<!--
    Maps request paths to flows in the flowRegistry; e.g. a path of
    /hotels/booking looks for a flow with id "hotels/booking"
-->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="order" value="0" />
</bean>

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

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

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

And my flow.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/webflow 
        http://www.springframework.org/schema/webflow/spring-webflow.xsd">

    <view-state id="step1" view="step1">
        <transition on="next" to="step2"/> 
        <transition on="cancel" to="cancel"/>
    </view-state>

    <view-state id="step2" view="step2">
        <transition on="previous" to="step1"/>
        <transition on="finish" to="success"/>
        <transition on="cancel" to="cancel"/>
    </view-state>

    <end-state id="success" view="flows/success"/>

    <end-state id="cancel" view="flows/cancel"/>

</flow>

I can successfully navigate to the views.

And my jsp is:

<html>
<head>
    <title>spring mvc web flow</title>
    <link rel="stylesheet" href="<c:url value="/resources/css/demo_page.css"/>" type="text/css"></link>
    <link rel="stylesheet" href="<c:url value="/resources/css/demo_table.css"/>" type="text/css"></link>
</head>
<body id="dt_example">
    <div id="container">
        <div>
            <p class="notice">This is step 1 of the web flow</p>
            <form id="step1" action="${flowExecutionUrl}" method="POST">
                <button id="cancel" type="submit" name="_eventId_cancel">Cancel</button>
                <button id="next" type="submit" name="_eventId_next">Next &gt;&gt;</button>
                <a href="${flowExecutionUrl}&_eventId=next">Next</a>
                <c:out value="${flowExecutionUrl}"/>

            </form>
        </div>
    <%@ include file="/WEB-INF/view/footer.jsp" %>
    </div>
</body>
</html>
Was it helpful?

Solution

Ok, got it... To start the flow, you need to use the flow id in the url. So in my case use the url 'http://localhost:8080/SpringMVC/flow' for the flow with the id of 'flow'. I was assuming the flow starts when you point to the view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top