May 2015
Intermediate to advanced
234 pages
4h 18m
English
In this recipe, you will learn how to display a form with initial values that the user can change.
Create an object containing the default values in the controller. In the view, use Spring form tags to generate the form using that object:
@ModelAttribute, which returns an object with default values:@ModelAttribute("defaultUser")
public User defaultUser() {
User user = new User();
user.setFirstName("Joe");
user.setAge(18);
return user;
}@RequestMapping("addUser")
public String addUser() {
return "addUser";
}<%@ taglib prefix="form" ...
Read now
Unlock full access