Allows to set an additional named variable which can be interpolated in the constraint violation message. The variable will be available for interpolation for all constraint violations generated for this constraint. This includes the default one as well as all violations created by the {@link ConstraintViolationBuilder}. To create multiple constraint violations with different variable values, this method can be called between successive calls to {@link javax.validation.ConstraintValidatorContext.ConstraintViolationBuilder#addConstraintViolation()}. For example:
{@code}public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) HibernateConstraintValidatorContext context = constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class ); context.addExpressionVariable( "foo", "bar" ); context.buildConstraintViolationWithTemplate( "${foo}" ) .addConstraintViolation(); context.addExpressionVariable( "foo", "snafu" ); context.buildConstraintViolationWithTemplate( "${foo}" ) .addConstraintViolation(); return false; } }
@param name the name under which to bind the parameter, cannot be {@code null}
@param value the value to be bound to the specified name
@return a reference to itself to allow method chaining
@throws IllegalArgumentException in case the provided name is {@code null}