Using Spring MVC3.1.2 @Controller annotation. Getting user object with GET method.
But after POST, if any if user field is not displayed in jsp/view , the value is lost.
Do not want to display certain fields to be edited, so not showing in edit page.
Do not want to use @SessionAttributes("user") as mentioned in some forums.
Do not want to use hidden variables. Too many fields. Any solution other than creating different beans?
Creating different beans is not option as some variable are displayed one forms and others in few forms.
Why is this feature taken out in spring 3.1.2 ? is there any solution? or I am missing something?
This was not the case in Springformcontroller in spring2.5. Object values form object were retained in the object if displayed or not. Why this not working in spring 3.1.2 @Controller annotation? Should revert back to spring2.5?
Here is the code snippet
Thanks. Any help /solution is appreciated.
@Controller
@RequestMapping("/users")
public class UserController {
//autowired service
@RequestMapping(value="/edit", method=RequestMethod.GET)
public String getEdit( Model model, @RequestParam("id") Long id) {
User user = userService.getUser(id);
if (user != null) {
model.addAttribute("user",user);
}
return "userForm";
}
@RequestMapping(value="/edit", method=RequestMethod.POST)
public String editUser(@ModelAttribute("user") User user , BindingResult result, @RequestParam("id") Long id) {
try {
userService.updateUser(user);
} catch (Exception ex) {
result.reject(ex.getMessage()) ;
return "userForm";
}
return "redirect:users";
}
...
//other methods
}
public class User implements java.io.Serializable, UserDetails {
private Long id;
private String username;
private String password;
private String email;
... loads of other fields with getter and setter


Reply With Quote