Francesco,
What you've done looks good to me. You may also want to add the following methods to BeanValidator and NamedBeanValidator as they are classes usually used by client code. BeanValidator adds automatic form-name resolution based on the object type. NamedBeanValidator allows declarative specification of the bean name (aka form name) in the application context.
BeanValidator
Code:
public void validate(Object obj, Errors errors, int page) {
validator.validate(getBeanName(obj.getClass()), obj, errors, page);
}
NamedBeanValidator
Code:
public void validate(Object obj, Errors errors, int page) {
if (beanName != null) {
validator.validate(beanName, obj, errors, page);
} else {
log.error("Cannot validate bean (" + obj.getClass()
+ "). NamedBeanValidator bean name not set. "
+ "Set the bean name in the validator configuration or "
+ "explicitly call validate(beanName, obj, errors).");
}
}
public void validate(String beanName, Object obj, Errors errors, int page) {
validator.validate(beanName, obj, errors, page);
}
Submit a patch to the JIRA if you want to contribute your code for others to use. It's good to see someone else inovating with the Commons Validator support.