Question

I'm trying to build a sample app using Thymeleaf and Spring WebFlow. I have a simple form where i have a text field in a object inside of the flowScope

this is the form:

<form id="mainForm" th:action="${flowExecutionUrl}">
<input type="text" id="selectedDate" th:value="${currentMonthStatus.selectedDate}" /> 
<input type="submit" name="_eventId" value="refresh" />
</form>

this is the flow:

    <?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-2.0.xsd"
parent="header">

<on-start>
    <evaluate expression="initServiceBean.getCurrentMonthSituation('me')"
        result="flowScope.currentMonthStatus" />
</on-start>

<view-state id="main" view="main/mainPage">
    <transition on="refresh" to="reload" />
</view-state>

<action-state id="reload">
    <evaluate
        expression="initServiceBean.getMonthSituation(flowScope.currentMonthStatus.selectedDate, 'me')"
        result="flowScope.currentMonthStatus" />
    <transition to="main" />
</action-state>
</flow>

this is my webflow configuration

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jee="http://www.springframework.org/schema/jee" xmlns:mvc="http://www.springframework.org/schema/mvc"
        xmlns:tx="http://www.springframework.org/schema/tx" xmlns:faces="http://www.springframework.org/schema/faces"
        xmlns:webflow="http://www.springframework.org/schema/webflow-config"
        xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
            http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.2.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">

        <context:component-scan base-package="it.addvalue.**.web.services" />

        <mvc:annotation-driven />

        <!-- <mvc:resources location="/" mapping="/resources/**" /> -->
        <mvc:resources location="/img/" mapping="/img/**" />
        <mvc:resources location="/css/" mapping="/css/**" />
        <mvc:resources location="/js/" mapping="/js/**" />
        <mvc:resources location="/less/" mapping="/less/**" />

        <faces:resources />

        <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
            <property name="flowRegistry" ref="flowRegistry" />
        </bean>

        <bean id="handlerMapping"
            class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />

        <!-- Resolves views selected for rendering by @Controllers to .xhtml resources 
            in the /WEB-INF/views directory -->
        <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
            <property name="prefix" value="/WEB-INF/views/" />
            <property name="suffix" value=".xhtml" />
        </bean>

        <!-- Dispatches requests mapped to flows to FlowHandler implementations -->
        <bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
            <property name="flowExecutor" ref="flowExecutor" />
        </bean>

        <!-- Executes flows: the central entry point into the Spring Web Flow system -->
        <webflow:flow-executor id="flowExecutor">
            <webflow:flow-execution-listeners>
                <webflow:listener ref="facesContextListener" />
            </webflow:flow-execution-listeners>
        </webflow:flow-executor>

        <!-- The registry of executable flow definitions -->
        <webflow:flow-registry id="flowRegistry"
            flow-builder-services="flowBuilderServices" base-path="/WEB-INF/flows">
            <webflow:flow-location-pattern value="/**/*-flow.xml" />
        </webflow:flow-registry>

        <!-- Configures the Spring Web Flow JSF integration -->
        <faces:flow-builder-services id="flowBuilderServices" 
            development="true" view-factory-creator="mvcViewFactoryCreator"  />

        <!-- A listener to create and release a FacesContext -->
        <bean id="facesContextListener"
            class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener" />

        <!-- Thymeleaf integration -->

        <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
            <property name="templateResolver" ref="templateResolver" />
        </bean>


        <bean id="templateResolver"
            class="org.thymeleaf.spring3.templateresolver.SpringResourceTemplateResolver">
            <property name="prefix" value="/thymeleaf/" />
            <property name="suffix" value=".html" />
            <property name="templateMode" value="HTML5" />
            <property name="cacheable" value="false"/>
        </bean>

        <bean id="thymeleafViewResolver" class="org.thymeleaf.spring3.view.AjaxThymeleafViewResolver">
            <property name="viewClass"
                value="org.thymeleaf.spring3.view.FlowAjaxThymeleafView" />
            <property name="templateEngine" ref="templateEngine" />
        </bean>

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

My problem is: the submit call a new flow instead of calling an action, where is the error?
It's my first time using WebFlow without JSF.

Was it helpful?

Solution

Approach 1:

    <input type="submit" name="_eventId_refresh" value="refresh" />

When event is signalled, Web Flow looks for name beginning with "_eventId _" and treats the remaining substring as the event id. So in above case, submitting _eventId_refresh becomes refresh. This practice is followed when there are several events that can be signaled from the same form.

Approach 2:

    <input type="submit" value="refresh" />
    <input type="hidden" name="_eventId" value="refresh" />

When event is signalled, Web Flow looks for name _eventId and uses its value as the event id. This practice is followed when there is only one event that can be signaled on the form.

When you submit by click of the button and no eventId is found then flow execution is getting refreshed and its not a new flow.

So change your event according to your form and try.

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