public interface ConstraintValidatorContext
ConstraintViolation
must be defined (either the default one,
of if the default ConstraintViolation
is disabled, a custom one).Modifier and Type | Interface and Description |
---|---|
static interface |
ConstraintValidatorContext.ConstraintViolationBuilder
ConstraintViolation builder allowing to optionally associate
the violation report to a sub path. |
Modifier and Type | Method and Description |
---|---|
ConstraintValidatorContext.ConstraintViolationBuilder |
buildConstraintViolationWithTemplate(String messageTemplate)
Return an constraint violation builder building an violation report
allowing to optionally associate it to a sub path.
|
void |
disableDefaultConstraintViolation()
Disable the default
ConstraintViolation object generation (which
is using the message template declared on the constraint). |
String |
getDefaultConstraintMessageTemplate() |
void disableDefaultConstraintViolation()
ConstraintViolation
object generation (which
is using the message template declared on the constraint).
Useful to set a different violation message or generate a ConstraintViolation
based on a different property.String getDefaultConstraintMessageTemplate()
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
ConstraintViolationBuilder
or any of its associated nested interfaces
an IllegalStateException
is raised.
If isValid returns false
, a ConstraintViolation
object will be built per ConstraintViolation report including the default one (unless
disableDefaultConstraintViolation()
has been called).
ConstraintViolation
objects 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 ConstraintValidatorContext
Here 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.