title: Replace default message for Constraint Validator
body: <p>I'm trying to change the default message of a Constraint Validator in Spring. </p>
  
  <p>I tried adding the new message depending on the validation error like this:</p>
  
  <pre><code>context.buildConstraintViolationWithTemplate("My custom message").addConstraintViolation();
  </code></pre>
  
  <p>for every case. </p>
  
  <pre><code>@Override
  public boolean isValid(MyData data, ConstraintValidatorContext ctx) {
      boolean valid = false;
      if (!StringUtils.isEmpty(data.getDocumentType())) {
          if (data.getDocumentType().equalsIgnoreCase("N")) {
              valid = isValidTypeN(data.getDocument());
              if(!valid) context.buildConstraintViolationWithTemplate("My custom message for type N").addConstraintViolation();
          } else if(data.getDocumentType.equalsIgnoreCase("R")){
              valid = isValidTypeR(data.getDocument());
              if(!valid) context.buildConstraintViolationWithTemplate("My custom message for type R").addConstraintViolation();
          } else if(data.getDocumentType.equalsIgnoreCase("P")) {
              valid = isValidTypeP(data.getDocument());
              if(!valid) context.buildConstraintViolationWithTemplate("My custom message for type P").addConstraintViolation();
          }
      }       
      return valid;
  }
  </code></pre>
  
  <p>But this is adding a new message not replacing the default message from the Constraint so when I show the errors in the form page, it shows both of them the default and the one I added instead of only the one I added dynamically.</p>