public interface HibernateConstraintValidatorContext extends ConstraintValidatorContext
ConstraintValidatorContext which allows to set additional message parameters for
interpolation.ConstraintValidatorContext.ConstraintViolationBuilder| Modifier and Type | Method and Description |
|---|---|
HibernateConstraintValidatorContext |
addExpressionVariable(String name,
Object value)
Allows to set an additional named variable which can be interpolated in the constraint violation message.
|
TimeProvider |
getTimeProvider()
Returns the provider for obtaining the current time, e.g.
|
HibernateConstraintValidatorContext |
withDynamicPayload(Object payload)
Allows to set an object that may further describe the violation.
|
buildConstraintViolationWithTemplate, disableDefaultConstraintViolation, getClockProvider, getDefaultConstraintMessageTemplate, unwrapHibernateConstraintValidatorContext addExpressionVariable(String name, Object value)
ConstraintViolationBuilder.
To create multiple constraint violations with different variable values, this method can be called
between successive calls to ConstraintValidatorContext.ConstraintViolationBuilder.addConstraintViolation().
For example:
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;
}
name - the name under which to bind the parameter, cannot be nullvalue - the value to be bound to the specified nameIllegalArgumentException - in case the provided name is nullTimeProvider getTimeProvider()
Future and Past
constraints.null. If no specific provider has been
configured during bootstrap, a default implementation using the current system time and the current
default time zone will be returned.HibernateConstraintValidatorContext withDynamicPayload(Object payload)
javax.validation.ConstraintViolation has to be serialized.payload - an object representing additional information about the violationCopyright © 2018 JBoss by Red Hat. All rights reserved.