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配置文件(上圖)。
基本上這是無法正常工作。
所以我想解決以下問題。
這些模型如何在沒有任何接線的情況下工作。我沒有使用webflow配置文件中的任何註釋bean定義(可能是這可能沒有正確連接)。
我可以將一個像字符串(在這種情況下是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;
}
}