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 expression variable which will be available as an EL variable during interpolation.
|
HibernateConstraintValidatorContext |
addMessageParameter(String name,
Object value)
Allows to set an additional named parameter which can be interpolated in the constraint violation message.
|
<C> C |
getConstraintValidatorPayload(Class<C> type)
Returns an instance of the specified type or
null if the current constraint validator payload isn't of
the given type. |
HibernateConstraintValidatorContext |
withDynamicPayload(Object payload)
Allows to set an object that may further describe the violation.
|
buildConstraintViolationWithTemplate, disableDefaultConstraintViolation, getClockProvider, getDefaultConstraintMessageTemplate, unwrap
HibernateConstraintValidatorContext addMessageParameter(String name, Object value)
ConstraintViolationBuilder
.
To create multiple constraint violations with different variable values, this method can be called
between successive calls to ConstraintViolationBuilder#addConstraintViolation()
.
For example:
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
HibernateConstraintValidatorContext context = constraintValidatorContext.unwrap( HibernateConstraintValidatorContext.class );
context.addMessageParameter( "foo", "bar" );
context.buildConstraintViolationWithTemplate( "{foo}" )
.addConstraintViolation();
context.addMessageParameter( "foo", "snafu" );
context.buildConstraintViolationWithTemplate( "{foo}" )
.addConstraintViolation();
return false;
}
name
- the name under which to bind the parameter, cannot be null
value
- the value to be bound to the specified nameIllegalArgumentException
- in case the provided name is null
HibernateConstraintValidatorContext 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 expression variable, cannot be null
value
- the value to be bound to the specified nameIllegalArgumentException
- in case the provided name is null
HibernateConstraintValidatorContext withDynamicPayload(Object payload)
javax.validation.ConstraintViolation
has to be serialized.payload
- an object representing additional information about the violation@Incubating <C> C getConstraintValidatorPayload(Class<C> type)
null
if the current constraint validator payload isn't of
the given type.type
- the type of payload to retrievenull
if the current constraint validator payload isn't of
the given typeHibernateValidatorConfiguration.constraintValidatorPayload(Object)
Copyright © 2019 JBoss by Red Hat. All rights reserved.