|
||||||||||
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 error must be defined (either the default one, of if the default error is disabled, a custom one).
Nested Class Summary | |
---|---|
static interface |
ConstraintValidatorContext.ErrorBuilder
Error builder allowing to optionally associate the error to a sub path. |
Method Summary | |
---|---|
ConstraintValidatorContext.ErrorBuilder |
buildErrorWithMessageTemplate(java.lang.String messageTemplate)
Return an error builder building an error allowing to optionally associate the error to a sub path. |
void |
disableDefaultError()
Disable the default error message and default ConstraintViolation object generation. |
java.lang.String |
getDefaultErrorMessageTemplate()
|
Method Detail |
---|
void disableDefaultError()
java.lang.String getDefaultErrorMessageTemplate()
ConstraintValidatorContext.ErrorBuilder buildErrorWithMessageTemplate(java.lang.String messageTemplate)
isValid returns false
, a ConstraintViolation
object will be built per error including the default one unless
disableDefaultError()
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 error, a new error builder has to be retrieved from
ConstraintValidatorContext
Here are a few usage examples:
// create new error with the default path the constraint is located on
context.buildErrorWithMessageTemplate( "way too long" )
.addError();
// create new error in the "street" subnode of the default path the constraint
// is located on
context.buildErrorWithMessageTemplate( "way too long" )
.addSubNode( "street" )
.addError();
//create new error in the "addresses["home"].city.name subnode of the default
// path the constraint is located on
context.buildErrorWithMessageTemplate( "this detail is wrong" )
.addSubNode( "addresses" )
.addSubNode( "country" )
.inIterable().atKey( "home" )
.addSubNode( "name" )
.addError();
- Parameters:
messageTemplate
- new uninterpolated error message.
- Returns:
- Returns an error builder
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |