繁体   English   中英

正在执行mvc控制器方法而不是执行评估表达式-Spring Web Flow

[英]Instead of executing evaluation expression, mvc controller method is being executing - Spring Web Flow

我是Spring Web Flow中的newbee。 我已经使用Spring Web Flow创建了一个示例项目。 在主页上,mvc控制器方法正在按预期执行并到达第二页。 从第二页开始,单击提交时必须执行一个评估表达式。 代替的是,首先执行的方法再次执行。 我可以看到表单上的操作只是$ {flowExecutionUrl}。 因此,RequestMapping获得了相同的URL。 因此执行旧方法。

  1. 是否可以在操作属性中更改uri,然后附加$ {flowExecutionUrl}。
  2. 我们如何确保流定义文件正在执行

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>

Claim-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()。

任何人都可以帮助确定实施的问题,如何解决该问题。 提前致谢

我不确定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请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM