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

Models as a method parameter marked with @Validated in a @Controller will only validate on the Default group [SPR-9537] #14171

Closed
spring-projects-issues opened this issue Jun 23, 2012 · 3 comments
Assignees
Labels
in: web

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jun 23, 2012

Brian Reindel opened SPR-9537 and commented

I am using Hibernate 4.2.0 and Spring 3.1.1.RELEASE.

Consider the following handler in a @Controller:

@RequestMapping(value = "/register", method = RequestMethod.POST)
public ModelAndView submit(@Validated(value={Default.class, RegisterFormSecondaryChecks.class}) RegisterForm registerForm)
		throws ControllerException
{
	/* Implementation... */
}

Now consider the following form bean:

public class RegisterForm {

    @NotEmpty(groups = {Default.class})
    @Email(groups = {RegisterFormSecondaryChecks.class})
    private String emailAddress;

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getEmailAddress() {
        return emailAddress;
    }
    
    @NotEmpty(groups = {Default.class})
    @Length(min = 6, max = 16, groups = {RegisterFormSecondaryChecks.class})
    private String password;

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPassword() {
        return password;
    }
    
    @NotEmpty(groups = {RegisterFormSecondaryChecks.class})
    private String reEnterPassword;

    public void setReEnterPassword(String reEnterPassword) {
        this.reEnterPassword = reEnterPassword;
    }

    public String getReEnterPassword() {
        return reEnterPassword;
    }
}

According to my understanding of the JSR 303 specification, the Default group should be validated. If it passes validation, then the RegisterFormSecondaryChecks validation group will be validated. However, if it doesn't pass validation, then the RegisterFormSecondaryChecks validation group will not be validated. In the scenario above, however, Spring is only validating the Default group. If I add the Default group to all constraints, then they will be validated (as a whole group). Only the Default group appears to be recognized.


Affects: 3.1.1

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 13, 2012

Rossen Stoyanchev commented

The scenario is not fully defined without information on what inputs (request parameters) are used. Ideally provide an issue project.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Sep 10, 2012

Rossen Stoyanchev commented

Brian Reindel, please comment.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Dec 12, 2018

Brian Clozel commented

Resolving for now due to lack of feedback.

@spring-projects-issues spring-projects-issues added type: bug in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web
Projects
None yet
Development

No branches or pull requests

2 participants