public interface ConstraintValidatorContext
ConstraintViolationmust be defined (either the default one, of if the default
ConstraintViolationis disabled, a custom one).
|Modifier and Type||Interface and Description|
|Modifier and Type||Method and Description|
Return an constraint violation builder building an violation report allowing to optionally associate it to a sub path.
Disable the default
ConstraintViolationobject generation (which is using the message template declared on the constraint). Useful to set a different violation message or generate a
ConstraintViolationbased on a different property.
ConstraintValidatorContext.ConstraintViolationBuilder buildConstraintViolationWithTemplate(String messageTemplate)
ConstraintViolation, one must call either one of the #addConstraintViolation() methods available in one of the interfaces of the fluent API. If another method is called after #addConstraintViolation() on
ConstraintViolationBuilderor any of its associated nested interfaces an
IllegalStateExceptionis raised. If
ConstraintViolationobject will be built per ConstraintViolation report including the default one (unless
disableDefaultConstraintViolation()has been called).
ConstraintViolationobjects generated from such a call contain the same contextual information (root bean, path and so on) unless the path has been overriden. To create a different
ConstraintViolation, a new constraint violation builder has to be retrieved from
ConstraintValidatorContextHere are a few usage examples:
// create new violation report with the default path the constraint is located on context.buildConstraintViolationWithTemplate( "way too long" ) .addConstraintViolation(); // create new violation report in the "street" subnode of the default path //the constraint is located on context.buildConstraintViolationWithTemplate( "way too long" ) .addNode( "street" ) .addConstraintViolation(); //create new violation report in the "addresses["home"].city.name" subnode //of the default path the constraint is located on context.buildConstraintViolationWithTemplate( "this detail is wrong" ) .addNode( "addresses" ) .addNode( "country" ) .inIterable().atKey( "home" ) .addNode( "name" ) .addConstraintViolation();
messageTemplate- new uninterpolated constraint message.
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.