FroMage wrote:
Page 42 it says that for Class-level constraints nothing is appended to the "propertyPath", yet the ConstraintContext.addError(String message, String property) takes a "property" parameter to specify the faulty property. How are we supposed to get the faulty property out of a ConstraintViolation set wit ConstraintContext.addError(message, property) then?
Not sure I follow you. If you want to redefine the message of a class level constraint, use addError(String)
If you want to apply it on a property of the class, use addError(String, String).
I reworded the Javadoc a little bit
Code:
/**
* Add a new error message to a given sub property <code>property</code>.
* This error message will be interpolated.
* <p/>
* If isValid returns false, a ConstraintViolation object will be built
* per error message including the default one unless #disableDefaultErrorMEssage()
* has been called.
* If the constraint being validated is not a class-level constraint,
* a ValidationException is raised.
*
* <p/>
*
* @param message new unexpanded error message
* @param property property name the ConstraintViolation is targeting
*
* @throws ValidationException if the constraint is not set on a class-level
*/
void addError(String message, String property);
[/quote]