Uploaded image for project: 'Bean Validation'
  1. BVAL-339

Support interpolation of dynamically set message parameters

    Details

    • Type: New Feature
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.1.0.Beta2
    • Fix Version/s: None
    • Component/s: spec-general
    • Labels:
      None
    • Last commented by a user?:
      true
    • Sprint:

      Description

      Based on a question on stackoverflow, there seem to be use cases for setting message parameters dynamically, e.g. to put a dynamically determined valid value into the message:

      @Future
      private Date shippingDate;
      
      public class MyFutureValidator implements ConstraintValidator<Future, Date> {
      
          public void initialize(Future constraintAnnotation) {}
      
          public boolean isValid(Date value, ConstraintValidatorContext context) {
      
              Date now = ...;
      
              if( value.before( now ) ) {
      
                  context.disableDefaultConstraintViolation();
                  context
                      .buildConstraintViolationWithTemplate( "Must be after {now}" )
                      .setValue( "now", now )
                      .addConstraintViolation();
      
                  return false;
              }
      
              return true;
          }
      }
      

      If we don't find enough time for this, we should at least add an unwrap() method on ConstraintValidatorContext to allow for provider specific implementations.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                4 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated: