protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintViolation<Object> violation) { Annotation annotation = violation.getConstraintDescriptor().getAnnotation(); if (annotation instanceof Constraints.ValidateWith) { Constraints.ValidateWith validateWithAnnotation = (Constraints.ValidateWith)annotation; if (violation.getMessage().equals(Constraints.ValidateWithValidator.defaultMessage)) { Constraints.ValidateWithValidator validateWithValidator = new Constraints.ValidateWithValidator(); validateWithValidator.initialize(validateWithAnnotation); Tuple<String, Object[]> errorMessageKey = validateWithValidator.getErrorMessageKey(); if (errorMessageKey != null && errorMessageKey._2 != null) { return errorMessageKey._2; } else { return new Object[0]; } } else { return new Object[0]; } } List<Object> arguments = new LinkedList<>(); String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field}; arguments.add(new DefaultMessageSourceResolvable(codes, field)); // Using a TreeMap for alphabetical ordering of attribute names Map<String, Object> attributesToExpose = new TreeMap<>(); violation.getConstraintDescriptor().getAttributes().forEach((attributeName, attributeValue) -> { if (!internalAnnotationAttributes.contains(attributeName)) { attributesToExpose.put(attributeName, attributeValue); } }); arguments.addAll(attributesToExpose.values()); return arguments.toArray(new Object[arguments.size()]); }
Constraints.ValidateWith validateWithAnnotation = (Constraints.ValidateWith)annotation; if (violation.getMessage().equals(Constraints.ValidateWithValidator.defaultMessage)) { Constraints.ValidateWithValidator validateWithValidator = new Constraints.ValidateWithValidator(); validateWithValidator.initialize(validateWithAnnotation); Tuple<String, Object[]> errorMessageKey = validateWithValidator.getErrorMessageKey(); if (errorMessageKey != null && errorMessageKey._1 != null) { errorMessage = errorMessageKey._1;
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintViolation<Object> violation) { Annotation annotation = violation.getConstraintDescriptor().getAnnotation(); if (annotation instanceof Constraints.ValidateWith) { Constraints.ValidateWith validateWithAnnotation = (Constraints.ValidateWith)annotation; if (violation.getMessage().equals(Constraints.ValidateWithValidator.defaultMessage)) { Constraints.ValidateWithValidator validateWithValidator = new Constraints.ValidateWithValidator(); validateWithValidator.initialize(validateWithAnnotation); Tuple<String, Object[]> errorMessageKey = validateWithValidator.getErrorMessageKey(); if (errorMessageKey != null && errorMessageKey._2 != null) { return errorMessageKey._2; } else { return new Object[0]; } } else { return new Object[0]; } } List<Object> arguments = new LinkedList<>(); String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field}; arguments.add(new DefaultMessageSourceResolvable(codes, field)); // Using a TreeMap for alphabetical ordering of attribute names Map<String, Object> attributesToExpose = new TreeMap<>(); violation.getConstraintDescriptor().getAttributes().forEach((attributeName, attributeValue) -> { if (!internalAnnotationAttributes.contains(attributeName)) { attributesToExpose.put(attributeName, attributeValue); } }); arguments.addAll(attributesToExpose.values()); return arguments.toArray(new Object[arguments.size()]); }
Constraints.ValidateWith validateWithAnnotation = (Constraints.ValidateWith)annotation; if (violation.getMessage().equals(Constraints.ValidateWithValidator.defaultMessage)) { Constraints.ValidateWithValidator validateWithValidator = new Constraints.ValidateWithValidator(); validateWithValidator.initialize(validateWithAnnotation); Tuple<String, Object[]> errorMessageKey = validateWithValidator.getErrorMessageKey(); if (errorMessageKey != null && errorMessageKey._1 != null) { errorMessage = errorMessageKey._1;
Constraints.ValidateWith validateWithAnnotation = (Constraints.ValidateWith)annotation; if (violation.getMessage().equals(Constraints.ValidateWithValidator.defaultMessage)) { Constraints.ValidateWithValidator validateWithValidator = new Constraints.ValidateWithValidator(); validateWithValidator.initialize(validateWithAnnotation); Tuple<String, Object[]> errorMessageKey = validateWithValidator.getErrorMessageKey(); if (errorMessageKey != null && errorMessageKey._1 != null) { errorMessage = errorMessageKey._1;
protected Object[] getArgumentsForConstraint(String objectName, String field, ConstraintViolation<Object> violation) { Annotation annotation = violation.getConstraintDescriptor().getAnnotation(); if (annotation instanceof Constraints.ValidateWith) { Constraints.ValidateWith validateWithAnnotation = (Constraints.ValidateWith)annotation; if (violation.getMessage().equals(Constraints.ValidateWithValidator.defaultMessage)) { Constraints.ValidateWithValidator validateWithValidator = new Constraints.ValidateWithValidator(); validateWithValidator.initialize(validateWithAnnotation); Tuple<String, Object[]> errorMessageKey = validateWithValidator.getErrorMessageKey(); if (errorMessageKey != null && errorMessageKey._2 != null) { return errorMessageKey._2; } else { return new Object[0]; } } else { return new Object[0]; } } List<Object> arguments = new LinkedList<>(); String[] codes = new String[] {objectName + Errors.NESTED_PATH_SEPARATOR + field, field}; arguments.add(new DefaultMessageSourceResolvable(codes, field)); // Using a TreeMap for alphabetical ordering of attribute names Map<String, Object> attributesToExpose = new TreeMap<>(); violation.getConstraintDescriptor().getAttributes().forEach((attributeName, attributeValue) -> { if (!internalAnnotationAttributes.contains(attributeName)) { attributesToExpose.put(attributeName, attributeValue); } }); arguments.addAll(attributesToExpose.values()); return arguments.toArray(new Object[arguments.size()]); }
/** * When dealing with @ValidateWith annotations, and message parameter is not used in * the annotation, extract the message from validator's getErrorMessageKey() method **/ protected String getMessageForConstraintViolation(ConstraintViolation<Object> violation) { String errorMessage = violation.getMessage(); Annotation annotation = violation.getConstraintDescriptor().getAnnotation(); if (annotation instanceof Constraints.ValidateWith) { Constraints.ValidateWith validateWithAnnotation = (Constraints.ValidateWith)annotation; if (violation.getMessage().equals(Constraints.ValidateWithValidator.defaultMessage)) { Constraints.ValidateWithValidator validateWithValidator = new Constraints.ValidateWithValidator(); validateWithValidator.initialize(validateWithAnnotation); Tuple<String, Object[]> errorMessageKey = validateWithValidator.getErrorMessageKey(); if (errorMessageKey != null && errorMessageKey._1 != null) { errorMessage = errorMessageKey._1; } } } return errorMessage; }