Skip to content
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

Support for validation groups in @Valid used by spring MVC [SPR-6373] #11039

Closed
spring-issuemaster opened this issue Nov 17, 2009 · 10 comments

Comments

@spring-issuemaster
Copy link
Collaborator

commented Nov 17, 2009

Pavla Nováková opened SPR-6373 and commented

It would be useful to be able to use validation groups in spring MVC as specified by JSR-303. With the improvement it should be possible to write something like:

@RequestMapping("/foo", method=RequestMethod.POST)
public void processFoo(@Valid(groups={Default.class, MyValidationGroup.class}) Foo foo) { ... }


Affects: 3.0 RC2

Issue Links:

  • #11035 Support for 'groups' in addition to @Valid for @MVC Controllers ("is duplicated by")
  • #11722 Add Group Class support to JSR-303 Validation using @Valid ("is duplicated by")
  • #12504 ValidationUtils: add support for Validation group interfaces

Referenced from: commits 0013317, 49a2aaf

54 votes, 53 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 24, 2009

Sam Brannen commented

Hi Pavla,

That's a very good point. In fact, I had a similar idea. ;)

Note, however, that @javax.validation.Valid does not support the groups attribute you proposed.

Thus, since @Valid is a part of the JSR 303 standard, Spring would have to provide a custom (Spring) annotation (or similar mechanism) to enable configuration of validation groups.

cheers,

Sam

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 24, 2009

Pavla Nováková commented

Hi Sam,

what you suggest - custom Spring annotation - is exactly what I mean. Yes, I'm aware that @javax.validation.Valid cannot be used for this purpose.

Best regards, Pavla

@spring-issuemaster

This comment has been minimized.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 6, 2011

Cemo Koc commented

I started to feel that this issue never will be addressed.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Nov 28, 2011

Juergen Hoeller commented

A related discussion over there at the JSR-303 EG: https://hibernate.onjira.com/browse/BVAL-208
We are watching these discussions closely, not least of it all since our use of @Valid in Spring MVC triggered them.

As for a solution for declarative group validation in Spring itself, we intended to wait on the JSR-303 EG going some such way for Bean Validation 1.1... However, the path is still not clear there, except maybe for the fact that @Valid itself won't see a groups attribute any time soon.

In any case, we do notice that this is a very popular Spring issue with many votes. Chances are that we'll sneak a solution into Spring 3.1 GA, or possibly 3.1.1.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Dec 3, 2011

Juergen Hoeller commented

Good news: This has finally been added in time for 3.1 GA, through a validation 'hint' mechanism in our SmartValidator interface and a custom @Valid annotation in our validation package. Validation groups can simply be specified through using that custom @Valid annotation like as follows:

@Valid(MyGroup.class)

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 29, 2012

Ben Flint commented

In 3.1.0.RELEASE, I believe the spring-specific annotation is @Validated, not @Valid.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Jan 30, 2012

Stefan Haberl commented

IMHO the new @Validated annotation works great, but I would have loved to be able to query the validation group that caused a bean validation to fail, which I think is still not possible: I would like to define a parameter in my method signature a long the lines of

@Validated(Errors.class, Warnings.class) BindingResult result

and then in the method body

if (result.hasErrors(Warnings.class)) {...}

I know I can work around this using more BindingResults in my method signature, but this is verbose and the long parameter lists soon turn ugly.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented May 25, 2012

Perit Bezek commented

Spring 3.1 may not support what you ask, but I believe this can be done by implementing a custom HandlerMethodArgumentResolver. You may need to create a custom annotation though, if the default resolver can handle @Validated BindingResult result type argument.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 12, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.