我是Spring Web Flow的新手。我使用spring web flow创建了一个示例项目。从主页,mvc控制器方法按照期望执行并到达第二页。从第二页开始,点击提交时必须执行一个评估表达式。而不是首先执行的方法再次执行。 我可以看到表单上的操作只是$ {flowExecutionUrl}。所以RequestMapping得到了相同的url。因此执行旧方法。
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的Submit按钮的click事件中,它正在执行ClaimController的getClaims()方法而不是saveNewClaim()。
任何人都可以帮助确定实施的问题,如何解决这个问题。 在此先感谢
答案 0 :(得分:0)
我不确定claim-flow.xml,但您可以在saveNewClaim方法中使用RequestMapping。
@RequestMapping(value = "/claims/", method = RequestMethod.POST)
public void saveNewClaim(Claim claim){
claimList.add(claim);
System.out.println("The claim has been added...");
}
我正在考虑这样的事情:
@Controller
public class ClaimController {
public static List<Claim> claimList = new ArrayList<Claim>();
@RequestMapping(value = "/claims/", method = RequestMethod.GET)
public void getClaims(){
System.out.println("Hi Claims");
}
@RequestMapping(value = "/claims/", method = RequestMethod.POST)
public void saveNewClaim(Claim claim){
claimList.add(claim);
System.out.println("The claim has been added...");
}
}
第一种方法加载表单。第二个响应来自此表单的POST请求。