@ModelAttribute binding defined globally for particular attribute rather than per method invocation [SPR-16083] #20632
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: backported
An issue that has been backported to maintenance branches
type: bug
A general bug
Milestone
Brice Roncace opened SPR-16083 and commented
Given this test controller (and java bean):
When exercising this controller with
bindTest?id=1
no binding will occur because theprepareBean2
method disables binding for thebean
model attribute even though a subsequent use of the@ModelAttribute
in theeditBean
method expects binding to occur.The unsatisfactory workarounds are to allow binding and insert an ignored
BindingResult
parameter in theprepareBean2
method so that if binding errors occur, they can be handled in theeditBean
method where they are expected:Or pull the
bean
out of the model to prevent binding in theprepareBean2
method:Note: in a real-world example these two
@ModelAttribute
annotated methods would not appear in the same class (e.g.@ControllerAdvice
would apply the initialprepareBean
method).Issue Links:
@ModelAttribute
Referenced from: commits b0ae8f6, bec1fc1
Backported to: 4.3.13
The text was updated successfully, but these errors were encountered: