Thanks Hardy for your response!
Meanwhile, I solved the problem the following way:
1. I defined an interface
DetailedValidation:
Code:
public interface DetailedValidation{
public String getDetails();
}
2. I created a new message interpolator:
Code:
public class DetailedMessageInterpolator implements MessageInterpolator {
@Override
@SuppressWarnings("unchecked")
public String interpolate(String message, Validator validator, MessageInterpolator defaultInterpolator) {
if (validator instanceof DetailedValidation) {
return ((DetailedValidation) validator).getDetails();
}
return defaultInterpolator.interpolate(message, validator, defaultInterpolator);
}
}
3. My validators that implement the
DetailedValidation interface look like this (in fact they extend an
AbstractDetailedValidation class containing a setter for details):
Code:
@Override
public boolean isValid(Object obj) {
try {
checkValid(obj);
setDetails(null);
return true;
} catch (ValidationException ve) {
setDetails(ve.getMessage());
return false;
}
}
I'm aware that this only works as long as you create your own ClassValidator instance:
Code:
ClassValidator<T> dataBeanValidator = new ClassValidator<T>(dataClass, new DetailedMessageInterpolator());
It works nicely for our use cases though, so anyone, feel free to post comments or possible side-effects / hiccups. Thanks in advance!
Best regards,
Pierre