我正在尝试使用Thymeleaf和Spring WebFlow构建示例应用程序。 我有一个简单的表单,我在flowScope
中的对象中有一个文本字段这是表格:
<form id="mainForm" th:action="${flowExecutionUrl}">
<input type="text" id="selectedDate" th:value="${currentMonthStatus.selectedDate}" />
<input type="submit" name="_eventId" value="refresh" />
</form>
这是流程:
<?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>
这是我的webflow配置
<?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>
我的问题是:提交调用新流而不是调用操作,错误在哪里?
这是我第一次在没有JSF的情况下使用WebFlow。
答案 0 :(得分:3)
方法1:
<input type="submit" name="_eventId_refresh" value="refresh" />
当发出事件信号时,Web Flow会查找以“_eventId _”开头的名称,并将剩余的子字符串视为事件ID。所以在上面的例子中,提交_eventId_refresh变为刷新。当有多个事件可以从同一表单发出信号时,会遵循这种做法。
方法2:
<input type="submit" value="refresh" />
<input type="hidden" name="_eventId" value="refresh" />
当发出事件信号时,Web Flow会查找名称_eventId并将其值用作事件ID。当只有一个事件可以在表单上发出信号时,就会遵循这种做法。
当您通过单击按钮提交并且未找到eventId时,流程执行将刷新,而不是新流程。
因此,请根据您的表单更改您的活动并尝试。