Thx for the answer, but...
With a bean level validator, I get for sure the whole bean in parameter, so I am able to do the validation, but it is not possible to state that a given field is in error... and this is the behavior you expect (excerpt from hibernate validator unit test:
Code:
public void testBeanValidator() throws Exception {
Vase v = new Vase();
ClassValidator<Vase> classValidator = new ClassValidator<Vase>( Vase.class );
InvalidValue[] invalidValues = classValidator.getInvalidValues( v );
assertEquals( 1, invalidValues.length );
assertNull( invalidValues[0].getPropertyName() );//<<<<<<
}
Note: this is the same issue as when using @AssertTrue on a method
I really need to validate ONE field, but for this validation, I need to access other fields...
One implementation suggestion (actually I already did it and it works fine...):
* add one interface
Code:
public interface ValidatorWholeBeanAware{}
* flag my validator with it:
Code:
public class MyValidator implements Validator<Assert>,ValidatorWholeBeanAware
* in ClassValidator around line 385 and 505 (methods= getInvalidValues(T, circ) and getInvalidValues(T, propertyName)):
replace
Code:
Object value = getMemberValue( bean, getter );
by
Code:
Object value=bean;
if (!(validator instanceof ValidatorWholeBeanAware)) {
value = getMemberValue( bean, getter );
}
Then MyValidator is still a property level validator (ie, InvalidValue.getPropertyName() will return the field name) but it can access the whole bean...
What do you think of this implementation ?
Thx very much
vincent