public interface Validation
ValidationImpl
) and can be injected in your
controller method.
There are several types of violations that can occur: field violations (on controller method fields), bean violations
(on an injected beans field) or general violations (deprecated). A controller using this validation can have
violations on his
parameters or, if you use a injected data container like a DTO or bean, you may have violations inside this object.
Each violation on a field (parameter or in an annotated bean) results in a FieldViolation
. This makes it
possible to validate all controller parameters at once. If an error appears while validating the controller
method parameters, it results in a violation which you can get using getFieldViolations().
If your injected bean contains violations, you should use getBeanViolations().Modifier and Type | Method and Description |
---|---|
void |
addBeanViolation(FieldViolation fieldViolation)
Add a bean violation.
|
void |
addFieldViolation(FieldViolation fieldViolation)
Add a field violation to the list of filed violations.
|
void |
addFieldViolation(java.lang.String field,
ConstraintViolation constraintViolation)
Add a violation to the given field
|
void |
addViolation(ConstraintViolation constraintViolation)
Deprecated.
|
java.util.List<FieldViolation> |
getBeanViolations()
Get all bean validations for that bean.
|
java.util.List<FieldViolation> |
getFieldViolations()
Get a complete list of all field violations.
|
java.util.List<FieldViolation> |
getFieldViolations(java.lang.String fieldName)
Get a complete list of field violations for a specified field.
|
java.util.List<ConstraintViolation> |
getGeneralViolations()
Deprecated.
|
boolean |
hasBeanViolation(java.lang.String name)
Checks if the validation has bean violation.
|
boolean |
hasBeanViolations()
Whether any violation occured while validating your beans
Note: For now, you can only have one bean in your controller method signature, so this is explicit.
|
boolean |
hasFieldViolation(java.lang.String field)
Whether the validation context has a violation for the given field
|
boolean |
hasViolations()
Whether the validation context has violations (including field and bean violations)
|
boolean hasViolations()
boolean hasFieldViolation(java.lang.String field)
void addFieldViolation(java.lang.String field, ConstraintViolation constraintViolation)
field
- The field to add the violation toconstraintViolation
- The constraint violation@Deprecated void addViolation(ConstraintViolation constraintViolation)
constraintViolation
- The constraint violationjava.util.List<FieldViolation> getFieldViolations()
java.util.List<FieldViolation> getFieldViolations(java.lang.String fieldName)
@Deprecated java.util.List<ConstraintViolation> getGeneralViolations()
void addFieldViolation(FieldViolation fieldViolation)
fieldViolation
- void addBeanViolation(FieldViolation fieldViolation)
beanName
- maybe the name of your dtofieldViolation
- the FieldViolation consisting of a cinstraintViolation and the fields
nameboolean hasBeanViolation(java.lang.String name)
name
- Name of the bean.boolean hasBeanViolations()
java.util.List<FieldViolation> getBeanViolations()
beanName
- Copyright © 2014. All Rights Reserved.