Skip to content

Provide integrated support for validation within @MVC lifecycle [SPR-4975] #9650

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

Closed
spring-projects-issues opened this issue Jul 2, 2008 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jul 2, 2008

Chris Beams opened SPR-4975 and commented

Today the @MVC programming model requires manual instantiation and invocation of Validator classes:

public String onSubmit(@ModelAttribute Customer customer, BindingResult result) {
new CustomerValidator().validate(customer, result);
if(result.hasErrors()) {
return "editAccount";
}
return "...";
}

It would be preferable to have validation be an integrated part of the @MVC lifecycle.

For instance, Validator instances could be annotated as @Component and be subject to component scanning. At any rate, whether declared via bean definitions or component scanned, registered Validator instances should be iterated through, and any returning true from Validator#supports() should be used to validate candidate objects.

Additionally, I believe the interface-based approach is preferable here, vs a @Validator approach, because the strong contract of supports()->validate() is a useful and expressive one. It would be sufficient to simply allow Validator instances to be component scanned. We just need to add iterating through and invoking registered validators to the lifecycle.


Issue Links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants