2014-03-14 33 views
0

我是webflow的新手,我在这里面临几个问题。基本上我想要将一个变量绑定到视图状态选择选项集并在下一个视图中使用它。为此,我使用了下面的代码。Spring Webflow中的数据绑定问题

<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> 

在这里,我可以访问的第一个视图,但不会当我点击任何一个按钮下一个视图。 这是我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> 

这是我patientInfo.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> 

在这里,我结合病人模型这一观点。

<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)的变量出价给一个视图(正如我在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; 
    } 

} 

回答

1

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

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