-
Notifications
You must be signed in to change notification settings - Fork 37.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@MVC should provide an "onBind" hook prior to automatic validation [SPR-6437] #11103
Comments
Sam Brannen commented The following is a description of a use case that requires this functionality.
A solution to this problem would be to add custom binding logic that removes empty Foos prior to execution of the Validator, but there is currently no hook in |
Sam Brannen commented The following technique suggested by Dave Syer could serve as a possible work-around in the interim. In an
DelegatingValidatorAdaptor could then effectively modify the model before delegating to the real validator. |
Dave Syer commented Since the binder is responsible for validation, I actually prefer my "workaround" to an additional method-level annotation. Maybe if DataBinder were to pick up a preValidate() method it would be nicer. And we should allow
|
Sam Brannen commented I would like to point out that the easiest work-around is simply to avoid using |
Rossen Stoyanchev commented Closing this issue due to the identified approach with invoking a validator directly. I should also mention that the |
Sam Brannen opened SPR-6437 and commented
When using
@Valid
to drive automatic validation of a model object, it is currently not possible to modify the bound model object prior to validation.With the SimpleFormController hierarchy it was straightforward to override BaseCommandController's onBind() or onBindAndValidate() methods to achieve custom binding; however, with
@MVC
it is currently not possible. Neither the WebBindingInitializer API nor an@InitBinder
method provides a mechanism to plug in custom binding.Note that this was not an issue prior to support for
@Valid
, since without@Valid
developers were responsible for executing validation code within a handler method.One possible solution would be to add support for an
@PostBinding
method or@PreValidation
method (or similar) which would be allowed to modify the model after binding but prior to executing the handler method.Affects: 3.0 RC2
Issue Links:
@MVC
request lifecycle@MVC
should provide a way to invoke custom code at preBind stage6 votes, 6 watchers
The text was updated successfully, but these errors were encountered: