Description:
|
Based on a [question|http://stackoverflow.com/questions/13623556/] 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:
{code} @Future private Date shippingDate; {code}
{code} public class MyFutureValidator implements ConstraintValidator<Future, Date> {
public void initialize(Future constraintAnnotation) {}
public boolean isValid(Date value, ConstraintValidatorContext context) {
Date now = ...;
if( value.
after
before
( now ) ) {
context.disableDefaultConstraintViolation(); context .buildConstraintViolationWithTemplate( "Must be after {now}" ) .setValue( "now", now ) .addConstraintViolation();
return false; }
return true; } } {code}
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.
|