I'm using Spring 4.3.7, and I got two form controllers with forms rendering using Spring form taglib in corresponding views. To preserve form data between requests (for rendering invalid forms) I store them in SessionAttributes.
LabCreateController:
@Controller
@RequestMapping(path = "/labs/create")
@SessionAttributes("form")
public class LabCreateController {
@ModelAttribute("form")
public LabCreateForm form() {
return new LabCreateForm();
}
@GetMapping
public String showForm() {
return "lab_create";
}
}
WallController:
@Controller
@RequestMapping(path = "/group/{id}/wall")
@SessionAttributes("form")
public class WallController {
@ModelAttribute("form")
public PostCreateForm form() {
return new PostCreateForm();
}
@GetMapping(path = "/new")
public String newPostGet() {
return "communities_newpost";
}
}
I open /labs/create
in browser, everything is fine. Then I open /group/4/wall/new
and get a following error:
Invalid property 'text' of bean class [...LabCreateForm]
i.e it means that attribute form
from LabCreateController
somehow passed to WallController
, though Spring documentation says:
Session attributes as indicated using this annotation correspond to a specific handler's model attributes.
I believe it means they shouldn't be shared between controllers. Also this answer says that it is so since Spring 3.
Is it a bug or I'm missing something? If not, what is the appropriate way of storing a form inside one controller?