public class ConstraintValidatorContextImpl extends Object implements ConstraintValidatorContext
ConstraintValidatorContext.ConstraintViolationBuilder
Constructor and Description |
---|
ConstraintValidatorContextImpl(PathImpl propertyPath,
ConstraintDescriptor<?> constraintDescriptor) |
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). |
ConstraintDescriptor<?> |
getConstraintDescriptor() |
String |
getDefaultConstraintMessageTemplate() |
List<MessageAndPath> |
getMessageAndPathList() |
public ConstraintValidatorContextImpl(PathImpl propertyPath, ConstraintDescriptor<?> constraintDescriptor)
public final void disableDefaultConstraintViolation()
ConstraintValidatorContext
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.disableDefaultConstraintViolation
in interface ConstraintValidatorContext
public final String getDefaultConstraintMessageTemplate()
getDefaultConstraintMessageTemplate
in interface ConstraintValidatorContext
public final ConstraintValidatorContext.ConstraintViolationBuilder buildConstraintViolationWithTemplate(String messageTemplate)
ConstraintValidatorContext
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
ConstraintValidatorContext.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();
buildConstraintViolationWithTemplate
in interface ConstraintValidatorContext
messageTemplate
- new uninterpolated constraint message.public final ConstraintDescriptor<?> getConstraintDescriptor()
public final List<MessageAndPath> getMessageAndPathList()
Copyright © 2014 JBoss by Red Hat. All Rights Reserved.