I am working on a Spring 3 project and always check if a @ModelAttribute is null, if so I redirect the user to an error page.
@Controller
@SessionAttributes({"myCommand"})
public class MyController {
@ModelAttribute("myCommand")
public MyCommand populate(HttpServletRequest request) {
return new MyCommand();
}
@RequestMapping(value="/user/saveFoo", method=RequestMethod.POST)
public String saveFoo(HttpServletRequest request, @ModelAttribute("myCommand") MyCommand myCommand) {
if(myCommand == null) {
// Add invalid session error here.
return "error.htm";
}
...
...
}
}
What I want to know is if this check is necessary. The command is a session attribute and it is created using populate method of the controller when necessary. Thus the command can never be null as long as the session is alive.
What I don't know is what happens when the session is expired. Does the controller create the model attribute again? If so then the command object can never be null regardless of the state of the session.
Thanks for any help.