addValidationErrors(violations.toArray(new ConstraintViolation[0]), action, valueStack, null);
}
private void addValidationErrors(ConstraintViolation[] violations, Object action, ValueStack valueStack, String parentFieldname) {
if (violations != null) {
ValidatorContext validatorContext = new DelegatingValidatorContext(action);
for (ConstraintViolation violation : violations) {
//translate message
String key = violation.getMessage();
//push the validator into the stack
valueStack.push(violation.getContext());
String message = key;
try {
message = validatorContext.getText(key);
} finally {
valueStack.pop();
}
if (isActionError(violation)) {
LOG.debug("Adding action error '#0'", message);
validatorContext.addActionError(message);
} else {
ValidationError validationError = buildValidationError(violation, message);
// build field name
String fieldName = validationError.getFieldName();
if (parentFieldname != null) {
fieldName = parentFieldname + "." + fieldName;
}
LOG.debug("Adding field error [#0] with message '#1'", fieldName, validationError.getMessage());
validatorContext.addFieldError(fieldName, validationError.getMessage());
// don't add "model." prefix to fields of model in model driven action
if ((action instanceof ModelDriven) && "model".equals(fieldName)) {
fieldName = null;
}