我是Spring Web Flow中的newbee。我使用spring web flow創建了一個示例項目。在主頁上,mvc控制器方法按照期望執行併到達第二頁。從第二頁開始,點擊提交一個評估表達式即可執行。而不是先執行的方法再次執行。 我可以看到表單上的操作只有$ {flowExecutionUrl}。所以RequestMapping獲得相同的URL。因此執行舊的方法。而不是執行評估表達式,mvc控制器方法正在執行 - Spring Web Flow
- 是否可以更改操作屬性中的uri,然後附加$ {flowExecutionUrl}。
- 我們怎樣才能確保流程定義文件被執行
Servlet的context.xml中
<context:annotation-config/>
<context:component-scan base-package="com.metlife.claim"/>
<bean class=
"org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<value>
/claim/=flowController
</value>
</property>
<property name="alwaysUseFullPath" value="true"/>
</bean>
<bean class=
"org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<bean class=
"org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<bean id="viewResolver" class=
"org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="flowController" class=
"org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>
<flow:flow-executor id="flowExecutor" flow-registry="flowRegistry"/>
<flow:flow-registry id="flowRegistry"
flow-builder-services="flowBuilderServices">
<flow:flow-location path="/WEB-INF/flows/claims-flow.xml"/>
</flow:flow-registry>
<flow:flow-builder-services id="flowBuilderServices"
view-factory-creator="viewFactoryCreator"/>
<bean id="viewFactoryCreator" class=
"org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers">
<list>
<ref bean="viewResolver"/>
</list>
</property>
</bean>
</beans>
要求,flow.xml
<?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">
<!-- <view-state id="claims" view="addClaims"> -->
<view-state id="claims" model = "viewScope.claim">
<transition to="claimsEntered" on="submit">
<!-- <evaluate expression="claimController.saveNewClaim(viewScope.claim)"></evaluate> -->
</transition>
</view-state>
<action-state id="claimsEntered">
<evaluate expression="claimController.saveNewClaim(viewScope.claim)"></evaluate>
<transition to="claims"></transition>
</action-state>
</flow>
ClaimController.java
@Controller
public class ClaimController {
public static List<Claim> claimList = new ArrayList<Claim>();
@RequestMapping(value = "/claims/")
public void getClaims(){
System.out.println("Hi Claims");
}
public void saveNewClaim(Claim claim){
claimList.add(claim);
System.out.println("The claim has been added...");
}
}
claims.jsp
<form modelAttribute = "claim" action= "${flowExecutionUrl}">
<table>
<tr>
<td>Id</td>
<td><input type = "text" path="id" name = "id"/></td>
<tr>
<tr>
<td>Name</td>
<td><input type = "text" path="id" name = "name"/></td>
<tr>
<tr>
<td>Age</td>
<td><input type = "text" path="id" name = "age"/></td>
<tr>
<tr>
<td>Amount</td>
<td><input type = "text" path="id" name = "amount"/></td>
<tr>
<tr>
<td>Region</td>
<td><input type = "text" path="id" name = "region"/></td>
<tr>
<tr>
<td>
<input type = "submit" id = "submit" name = "_eventId_submit" value = "Submit"></td></tr>
</table>
</form>
針對home.jsp
<body>
<h1>
</h1>
<P> <a href="claims/" >Claims</a> </P>
</body>
在從claims.jsp提交按鈕的點擊事件,則執行getClaims的ClaimController代替saveNewClaim(()方法)。
任何人都可以幫忙找出執行過程中出了什麼問題,怎麼才能解決這個問題。 在此先感謝
是的。對於Spring MVC,你是對的。如果我們使用值指定RequestMapping,則Web流程不會出現在圖片中 – Mahi