2016-01-12 59 views
0

我有Spring 3應用程序,它將Tiles2作爲視圖解析器。每當我點擊「提交」按鈕時,應該顯示下一個jsp頁面,但它保持在同一頁面上。下一個狀態在春季Web流程中沒有被調用

我在/ 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空白和下一屏幕上不顯示。我是否缺少一些配置或發生了什麼問題?請幫忙。

回答

0

@如果你的配置看起來很好。衆所周知,SWF在解決問題時非常直觀。嘗試插入一個記錄到你的流量是這樣的:

Printing log from flow.xml

,並確定其中的「流」的執行被中斷。一旦你隔離的位置。嘗試進入流程代碼...我懷疑有吞噬異常的情況。

可能的答案:

如果我猜的話(即使你的配置看起來是正確的)。我懷疑SWF/tiles不會解析視圖名稱'studentReg'。嘗試通過創建一個單獨的流程來隔離這種情況,並查看是否可以導航到視圖studentReg。您也可以進入Tiles解析器邏輯來確定它正在被定位。

另外:

在我看來,這是不好的做法,把同一個名字給您viewStateId,過渡和的viewName(即 'studentReg')。當這樣的問題出現時,我認爲這會讓問題更難解決。最好附加一個後綴給他們。 (即studentRegVsId,studentRegViewName等)來創建一個區別。

+0

感謝您的幫助。其實我對它的理解如下:1]增加了flow-builder-services和mvcViewFactoryCreator。另外,我通過在index.jsp頁面中添加流標識來啓動流程,因爲我正在將它重定向到登錄頁面。 –