我不明白爲什麼我的字段值的用戶類正在消失,當我試圖在窗體之間導航。如何在表單之間導航時修復擦除字段?
@Controller
public class WizardController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String userForm(@ModelAttribute("user") User user) {
return "form/userForm";
}
@RequestMapping(value = "/user", method = RequestMethod.POST)
public String processedForm(@ModelAttribute("user") User user, BindingResult result,
ModelMap model) {
if (result.hasErrors()) {
return "form/userForm";
}
ArrayList<String> p = new ArrayList<String>();
p.add("add_user");
p.add("delete_user");
model.addAttribute("permissions", p);
model.addAttribute("user", user);
return "form/permissionForm";
}
@RequestMapping(value = "/show", method = RequestMethod.POST)
public String show(@ModelAttribute("user") User user, BindingResult result) {
if (result.hasErrors()) {
System.out.println("Error");
return "show";
} else {
System.out.println(user);
return "show";
}
}
}
我permissionForm.jsp
<form:form action="/show" method="post" modelAttribute="user">
<form:errors path="*" cssClass="errorblock" element="div"/>
<p>
<form:select path="permissions">
<form:options items="${permissions}"/>
</form:select>
</p>
<p><input type="submit" value="Add"/></p>
</form:form>
userForm.jsp
<form:form action="/user" method="post" modelAttribute="user">
<form:errors path="*" cssClass="errorblock" element="div"/>
<p><form:input path="name" placeholder="Name"/></p>
<p><form:input path="age" placeholder="Age"/></p>
<p><form:input path="email" placeholder="Email"/></p>
<p><form:input path="password" placeholder="Password"/></p>
<p><input type="submit"></p>
</form:form>
在show.jsp我使我的用戶
${user}
而且POJO類
public class User implements Serializable {
private String name;
private String email;
private String password;
private Integer age;
private List<String> permissions;
// getters, setters, toString
}
輸出:用戶{name ='null',email ='null',password ='null',age = null,permissions = [delete_user]}。我需要一個完整的對象,像這樣:
用戶{name ='John',email='[email protected]',密碼='12345',年齡= 21,權限= [delete_user]}。
感謝您的任何幫助。
你看着衝刺網絡的流程? http://projects.spring.io/spring-webflow/ – cfrick