私が使っている便利なヘルパークラス-
public final class ValidationHelper {
public static <TEntity> void invokeNestedValidator(Validator validator, TEntity entity, Errors errors, String subPath) {
try {
errors.pushNestedPath(subPath);
ValidationUtils.invokeValidator(validator, entity, errors);
} finally {
errors.popNestedPath();
}
}
public static <TEntity> void invokeNestedValidatorForList(Validator validator, List<TEntity> entities, Errors errors, String subPathRoot) {
for (int index = 0; index < entities.size(); index++) {
invokeNestedValidator(validator, entities.get(index), errors, subPathRoot + "[" + index + "]");
}
}
private ValidationHelper() {}
}