thymeleaf / thymeleaf-docs

Thymeleaf documentation
Apache License 2.0
44 stars 54 forks source link

Make a point about the need for the form-backing bean name to match the name given at the Spring side #56

Open danielfernandez opened 6 years ago

danielfernandez commented 6 years ago

The name given to the form-backing bean variable used in <form th:object="${someBean} ...> should match the name assigned by Spring at the controller side, either because the name of the class matches:

@RequestMapping("/do")
public String something(final SomeBean form, final Errors errors) {
    ...
}

...or because a @ModelAttribute annotation has been added to force that name to be the one used:

@RequestMapping("/do")
public String something(@ModelAttribute("someBean") final Form form, final Errors errors) {
    ...
}

Failing to do so will result in Thymeleaf being unable to detect bean validation errors at the view side. See thymeleaf/thymeleaf-spring#169.

However, this is not mentioned in the documentation (though it is done at the STSM example application). We should mention it explicitly somehow.