|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface ConstraintValidatorContext
Provide contextual data and operation when applying a given constraint validator.
At least one ConstraintViolation
must be defined (either the default one,
of if the default ConstraintViolation
is disabled, a custom one).
Nested Class Summary | |
---|---|
static interface |
ConstraintValidatorContext.ConstraintViolationBuilder
ConstraintViolation builder allowing to optionally associate
the violation report to a sub path. |
Method Summary | |
---|---|
ConstraintValidatorContext.ConstraintViolationBuilder |
buildConstraintViolationWithTemplate(java.lang.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). |
java.lang.String |
getDefaultConstraintMessageTemplate()
|
Method Detail |
---|
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.
java.lang.String getDefaultConstraintMessageTemplate()
ConstraintValidatorContext.ConstraintViolationBuilder buildConstraintViolationWithTemplate(java.lang.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();
- Parameters:
messageTemplate
- new uninterpolated constraint message.
- Returns:
- Returns an constraint violation builder
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2009, 2010, Oracle Corporation and/or its affiliates. All Rights Reserved. Use is subject to license terms.
Generated on 4-June-2010 04:34