Wednesday, August 7, 2013

Nested validation of an List

Hi,

I think I solved the problem.

I modified the CustomerValidator.java

Code:
public class CustomerValidator implements Validator {

 private AddressValidator addressValidator;
 
 public AddressValidator getAddressValidator() {
  return addressValidator;
 }

 public void setAddressValidator(AddressValidator addressValidator) {
  this.addressValidator = addressValidator;
 }

 public boolean supports(Class clazz) {
  return clazz.equals(Customer.class);
 }

 public void validate(Object obj, Errors errors) {
  Customer customer = (Customer) obj;
  ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required.name", "Name muss gesetzt sein");
  int i=0;
  for (Address address : customer.getAddresses()) {
   errors.pushNestedPath("addresses["+i+"]");
   ValidationUtils.invokeValidator(this.addressValidator, address, errors);
   errors.popNestedPath();
   i++;
  }  
 }

}
I hope this is correct and it helps.
Last edited by rognox; Aug 12th, 2009 at 09:59 AM.

http://forum.springsource.org/showthread.php?76132-Nested-validation-of-an-List

No comments:

Post a Comment