Using the model attribute as a bean is not recommended. This is useful for manipulating form data before it is stored in the database.
@ModelAttribute("formAttribute") is created when you specify it as a parameter in your method:
public void getForm(@ModelAttribute("formAttribute") Form form) { }
It is created before each method call, calling it contruct:
@ModelAttribute("formAttribute") public Form getForm() { return new Form(); }
If it is not specified in the method parameter, it does not exist.
You can add your @ModelAttribute to the session by specifying @SessionAttributes on your controller:
@Controller @SessionAttributes("formAttribute") public HelloController
Then it is initialized once when you first use it, and is destroyed when you destroy it, calling:
public void finalStep(SessionStatus status) { status.setComplete(); }
I think that with the @SessionAttributes combination it is relatively easy to create a magic stream.
rduga source share