views:

787

answers:

1

Hi,

I have a command class named Parent as follows:

public class Parent {

    private List<Child> childList;

    // getters and setters

}

And a Child class according to

public class Child {

    @NotBlank
    private String name;

    @NotBlank
    private String email;

    @NotBlank
    private Integer age;

}

In Spring validation module, i have been notice a @Cascade annotation.

Question: Does it work in collection-based property as in childList property ? If so, how can i use it ?

regards,

+1  A: 

With Hibernate Validator 4.0.0 Beta2, you can.

It based on JSR-303 Bean Validation.

Annotate Your List with @Valid to validate the content of the List

@Valid
private List<Child> childList;

Now validate:

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Parent>> constraintViolations = validator.validate(Parent);
Niels Peter Strandberg
Does Spring-MVC support for it ?
Arthur Ronald F D Garcia
You can do:for(ConstraintViolation<Parent> constraint : validator().validate(parent)) { bindingResult.rejectValue(constraint.getPropertyPath(), null, constraint.getMessage()); }
Niels Peter Strandberg
Trank you, Niels. I will take your advice. UPvote. regards
Arthur Ronald F D Garcia