web/play-java-forms/src/main/java/play/data/Form.java
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;
        }
      }
    }
    if (annotation instanceof Constraints.ValidatePayloadWith) {
      Constraints.ValidatePayloadWith validatePayloadWithAnnotation =
          (Constraints.ValidatePayloadWith) annotation;
      if (violation.getMessage().equals(Constraints.ValidatePayloadWithValidator.defaultMessage)) {
        Constraints.ValidatePayloadWithValidator validatePayloadWithValidator =
            new Constraints.ValidatePayloadWithValidator();
        validatePayloadWithValidator.initialize(validatePayloadWithAnnotation);
        Tuple<String, Object[]> errorMessageKey = validatePayloadWithValidator.getErrorMessageKey();
        if (errorMessageKey != null && errorMessageKey._1 != null) {
          errorMessage = errorMessageKey._1;
        }
      }
    }

    return errorMessage;
  }
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;
        }
      }
    }
    if (annotation instanceof Constraints.ValidatePayloadWith) {
      Constraints.ValidatePayloadWith validatePayloadWithAnnotation =
          (Constraints.ValidatePayloadWith) annotation;
      if (violation.getMessage().equals(Constraints.ValidatePayloadWithValidator.defaultMessage)) {
        Constraints.ValidatePayloadWithValidator validatePayloadWithValidator =
            new Constraints.ValidatePayloadWithValidator();
        validatePayloadWithValidator.initialize(validatePayloadWithAnnotation);
        Tuple<String, Object[]> errorMessageKey = validatePayloadWithValidator.getErrorMessageKey();
        if (errorMessageKey != null && errorMessageKey._1 != null) {
          errorMessage = errorMessageKey._1;
        }
      }
    }

    return errorMessage;
  }
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 ; } } } if ( annotation instanceof Constraints . ValidatePayloadWith ) { Constraints . ValidatePayloadWith validatePayloadWithAnnotation = ( Constraints . ValidatePayloadWith ) annotation ; if ( violation . getMessage ( ) . equals ( Constraints . ValidatePayloadWithValidator . defaultMessage ) ) { Constraints . ValidatePayloadWithValidator validatePayloadWithValidator = new Constraints . ValidatePayloadWithValidator ( ) ; validatePayloadWithValidator . initialize ( validatePayloadWithAnnotation ) ; Tuple < String , Object [ ] > errorMessageKey = validatePayloadWithValidator . getErrorMessageKey ( ) ; if ( errorMessageKey != null && errorMessageKey . _1 != null ) { errorMessage = errorMessageKey . _1 ; } } } return errorMessage ; }
When dealing with @ValidateWith or @ValidatePayloadWith annotations, and message parameter is
not used in the annotation, extract the message from validator's getErrorMessageKey() method

@param violation the constraint violation.
@return the message associated with the constraint violation.
When dealing with @ValidateWith or @ValidatePayloadWith annotations and message parameter is not used in the annotation extract the message from validator s getErrorMessageKey () method