I love this feature and really hope this will become part of the EJB3 spec if not part or JSE itself someday.
The missing feature I find is when using the @Valid annotation to perform recursive validations.
Imagine a simple object graph. We have Customer which has Contact which has firstName, lastName, phone, fax, email. Phone and fax are instances of blah.model.Phone.
In Customer
@Valid
public Contact getContact() ...
In Contact
@Valid
public Phone getPhone() ...
@Valid
public Phone getFax() ...
In Phone
@Pattern(regex=PHONE_REGEXP, message="must match {regex}")
public String getNumber()...
now we code:
Code:
ClassValidator<Customer> customerValidator = new ClassValidator(Customer.class);
InvalidValue[] validationMessages = customerValidator.getInvalidValues(customer);
for (InvalidValue value : validationMessages) {
log.debug("getBean() = " + value.getBean());
log.debug("getBeanClass() = " + value.getBeanClass());
log.debug("getMessage() = " + value.getMessage());
log.debug("getPropertyName() = " + value.getPropertyName());
log.debug("getValue() = " + value.getValue());
errors.rejectValue(value.getPropertyName(), value.getMessage(), value.getMessage());
}
// The errors bit is from Spring, and just how I would capture the message and return it to the view layer.
If I have junk in my phone and fax values, the InvalidValue array tells me that I have a problem in Class Phone, propertyName number for both phone and fax.
What we need is a property to tell me the method hierarchy that was traversed to generate the validation error.
Something like a callStack returning a string: customer.contact.fax.number.