java - Spring Webflow 中的数据绑定(bind)问题

标签 java spring data-binding spring-webflow autowired

我是 webflow 的新手,在这里面临几个问题。基本上我想将一个变量绑定(bind)到 View 状态选择选项集并在下一个 View 中使用它。为此,我使用了以下代码。

<var name="flowScope.jobIdString" class="java.lang.String" />

<input name="userId" type="java.lang.Long" />

<on-start>
    <set name="userId" value="1234"></set>
</on-start>

<view-state id="startJob" view="/WEB-INF/jsp/startJob.jsp">

    <on-entry>
        <evaluate expression="jobService.getAllJobsForUser(userId)"
            result="flowScope.jobs">
            </evaluate>
    </on-entry>
    <transition on="createNew" to="createNewJob" />
    <transition on="editJob" to="editJob" />
</view-state>

<action-state id="createNewJob">
    <evaluate expression="patientBean" result="flowScope.patient" />
    <transition to="patientinfo" />
</action-state>

<action-state id="editJob">
    <evaluate expression="patientService.getPatientInfo(jobId)"
        result="flowScope.patient" />
    <transition to="patientinfo" />
</action-state>

<view-state id="patientinfo" model="patient"
    view="/WEB-INF/jsp/patientInfo.jsp">
</view-state>

在这里,当我单击任一按钮时,我可以访问第一个 View ,但无法进入下一个 View 。 这是我的startjob.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>



    <select size="8" name="jobIdString">
        <c:forEach items="${jobs}" var="job">
            <option value="job.id">${job.name}</option>
        </c:forEach>
    </select>

    <br />

    <input type="submit" name="_eventId_createNew" value="createNew">
    <input type="submit" name="_eventId_editJob" value="editJob">

</body>
</html>

这是我的病人Info.jsp 文件

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <form:form modelAttribute="patient">
        <form:hidden path="id" />
        <table>
            <tr>
                <td>Name:</td>
                <td><form:input path="name" /></td>
            </tr>
            <tr>
                <td>Age:</td>
                <td><form:input path="age" /></td>
            </tr>
            <tr>
                <td><input type="submit" value="Save and Close" /></td>
                <td><input type="submit" value="Save and Continue" /></td>
            </tr>
        </table>
    </form:form>
</body>
</html>

在这里,我将患者模型绑定(bind)到该 View 。

<webflow:flow-registry id="flowRegistry">
    <webflow:flow-location path="/WEB-INF/flow/webflow-flow.xml"
        id="webflow" />
</webflow:flow-registry>
<webflow:flow-executor id="flowExecutor"
    flow-registry="flowRegistry" />
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="order" value="0" />
</bean>
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    <property name="flowExecutor" ref="flowExecutor" />
</bean>

<bean id="jobService" class="com.b.webfolwprototype.service.JobService" />
<bean id="patientService" class="com.brandix.webfolwprototype.service.PatientService"></bean>

<bean id="patientBean" class="com.b.webfolwprototype.model.Patient"
    scope="prototype" />

<bean id="jobBean" class="com.b.webfolwprototype.model.Job"
    scope="prototype" />

这是我的 webflow 配置文件(上面)。

基本上这不能正常工作。

  1. 所以我也想解决以下这些问题。

  2. 这些模型如何在没有任何接线的情况下工作。我没有使用 webflow 配置文件中的任何注释 bean 定义(可能没有正确连接)。

  3. 我可以将像字符串这样的变量(在本例中为 jobId)投标给 View (正如我在 startjob.jsp 中尝试过的那样)如果这是错误的,该怎么办?

这是我的 PatientService

public class PatientService {

public void save(Patient patient) {
    System.out.println("save patinet");
}

public Patient getPatientInfo(Long jobId){
    Patient patient = new Patient();
    patient.setAge(35);
    patient.setName("test name");
    return patient;
}

}

这是我的 JobService

public class JobService {

public List<Job> getAllJobsForUser(Long userId) {

    ArrayList<Job> jobList = new ArrayList<Job>();
    Job job1 = new Job();
    job1.setId((long) 1234);
    job1.setName("Test Job Name");

    Job job2 = new Job();
    job2.setId((long) 1235);
    job2.setName("Test Job Name 2");

    jobList.add(job1);
    jobList.add(job2);
    return jobList;
}

}

这些是我的模型

    public class Job implements Serializable {

    private static final long serialVersionUID = 4979685043689356058L;
    private Long id;
    private String name;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}


public class Patient implements Serializable {

    private static final long serialVersionUID = -1541400280884340541L;
    private String name;
    private int age;
    private Long patientId;

    public Long getPatientId() {
        return patientId;
    }

    public void setPatientId(Long patientId) {
        this.patientId = patientId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int i) {
        this.age = i;
    }

}

最佳答案

您的流程进入 View startjob.jsp,这是启动点。从这里开始,当您单击指定的按钮时,swf 不知道如何恢复流程。因此,为了恢复流程,请在 startjob.jsp 中包含以下内容:

     <input type="hidden" name="_flowExecutionKey" value="${flowExecutionKey}">

关于java - Spring Webflow 中的数据绑定(bind)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22397143/

相关文章:

java - 无法在WebSphere服务器7中部署Maven项目Ear

java - 向 JApplet 显示图像?

Spring Boot 单页应用程序 - 将每个请求转发到 index.html

java - 无法使用 spring boot jpa 创建新表

silverlight - 使用数据绑定(bind)实现 MVVM 模式时,Silverlight 应用程序的性能是否会受到影响?

WPF DataGrid 取消选择更改

java - 当我在 java swing 中单击 JDatePicker 中的其他位置时,如何关闭弹出 DatePicker?

java - 在 Java 中,如何从另一个数组中获取数组名称后将其用作数组?

java - Spring中如何在非组件类中实现缓存

asp.net - 自动将 ASP.NET FormView 绑定(bind)到新插入的记录