【问题标题】:Next state is not getting called in spring web flow在 Spring Web Flow 中没有调用下一个状态
【发布时间】:2016-01-12 10:29:18
【问题描述】:

我有 Spring 3 应用程序,其中 Tiles2 作为视图解析器。每当我单击“提交”按钮时,应该显示下一个 jsp 页面,但它会停留在同一页面上。

我在 /WEB-INF/flow 目录中有一个 WebFlow.xml 文件,JSP 也在同一个文件夹中。

我的配置如下: -servlet.xml

<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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:flow="http://www.springframework.org/schema/webflow-config"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/webflow-config
        http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
<mvc:annotation-driven/>
    <context:component-scan base-package="com.controller.*"/>

    <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>

    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>
<flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>

    <flow:flow-registry id="flowRegistry">
        <flow:flow-location path="/WEB-INF/flow/WebFlow.xml" id="flow"/>
    </flow:flow-registry>

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

    <bean id="flowHandlerAdapter" class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor"/>
    </bean>
</beans>

WebFlow.xml

<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">

    <var name="studentRegForm" class="com.formbean.flows.StudRegForm"/>

    <view-state id="login" view="login">
        <transition on="studentReg" to="studentReg"/>
    </view-state>

    <view-state id="studentReg" view="studentReg" model="studentRegForm">
        <transition on="submitStudInfo" to="studConfirmPage"/>
    </view-state>

    <view-state id="studConfirmPage">
        <transition on="submit" to="showStoredPage"/>
        <transition on="Cancel" to="studentReg"/>
    </view-state>

    <end-state id="showStoredPage"/>
</flow>

login.jsp

<sf:form id="loginFrm" modelAttribute="loginForm" method="GET" action="${flowExecutionUrl}">
        <input type="text" name="_flowExecutionKey" value="${flowExecutionKey}"/>
        <input type="submit" value="Student Registration" name="_eventId_studentReg"/>
    </sf:form>

StudentReg.jsp

<sf:form id="studRegFrm" modelAttribute="studentRegForm" method="GET" action="${flowExecutionUrl}">
    <input type="text" name="_flowExecutionKey" value="${flowExecutionKey}"/>
        <table>
            <tr>
                <td><sf:label path="name">Please Enter Name:</sf:label></td>
                <td><sf:input path="name"/></td>
            </tr>
            <tr>
                <td><sf:label path="address">Please Enter Address:</sf:label></td>
                <td><sf:input path="address"/></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" name="_eventId_submitStudInfo" value="Submit"/></td>
            </tr>
        </table>
    </sf:form>

tiles.xml

<tiles-definitions>
    <definition name="mainLayout" template="/WEB-INF/jsp/layout/mainLayout.jsp">
        <put-attribute name="Title" value=""/>
        <put-attribute name="Header" value="/WEB-INF/jsp/layout/Header.jsp"/>
        <put-attribute name="Body" value=""/>
        <put-attribute name="Footer" value="/WEB-INF/jsp/layout/Footer.jsp"/>
    </definition>

    <definition name="login" extends="mainLayout">
        <put-attribute name="Title" value="Start Page"></put-attribute>
        <put-attribute name="Body" value="/WEB-INF/flow/login.jsp"/>
    </definition>

    <definition name="studentReg" extends="mainLayout">
        <put-attribute name="Title" value="Registration Page"></put-attribute>
        <put-attribute name="Body" value="/WEB-INF/flow/StudentReg.jsp"/>
    </definition>
</tiles-definitions>

但每当我单击 login.jsp 的提交按钮时,它会将 ${flowExecutionUrl} 和 ${flowExecutionKey} 显示为空白,并且下一个屏幕不显示。我是否缺少某些配置或出了什么问题?请帮忙。

【问题讨论】:

    标签: spring-webflow spring-3 tiles2


    【解决方案1】:

    @Aasif 您的配置“看起来”很好。 SWF 是出了名的不直观的故障排除。尝试像这样将记录器插入到您的流程中:

    Printing log from flow.xml

    并确定“流程”执行被中断的位置。一旦你隔离了位置。尝试进入流程代码...我怀疑正在吞噬异常。

    可能的答案:

    如果我不得不猜测(即使您的配置看起来正确)。我怀疑 SWF/tiles 没有解析视图名称“studentReg”。尝试通过创建一个单独的流来隔离这种情况,看看您是否可以导航到视图 studentReg。您还可以进入 Tiles 解析器逻辑以确保它被定位。

    还有:

    在我看来,给 viewStateId、transition 和 viewName 赋予相同的名称(即“studentReg”)是不好的做法。我认为当出现此类问题时,解决问题会更加困难。最好给它们附加一个后缀。 (即 studentRegVsId、studentRegViewName 等...)创建一个区别。

    【讨论】:

    • 感谢您的帮助。实际上我得到了它的灵魂:1]添加了flow-builder-services和mvcViewFactoryCreator。此外,当我从 index.jsp 页面重定向到登录页面时,我还通过在 index.jsp 页面中添加流 ID 来启动流。
    猜你喜欢
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多