Package ninja.validation
Interface Validation
-
- All Known Implementing Classes:
ValidationImpl
public interface Validation
This interface means the validation context (implemented byValidationImpl
) 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 aFieldViolation
. 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().- Author:
- James Roper, Philip Sommer
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addBeanViolation(FieldViolation fieldViolation)
Deprecated.void
addFieldViolation(String field, ConstraintViolation constraintViolation)
Deprecated.void
addFieldViolation(FieldViolation fieldViolation)
Deprecated.void
addViolation(ConstraintViolation constraintViolation)
Add a violationList<FieldViolation>
getBeanViolations()
Deprecated.List<FieldViolation>
getBeanViolations(String fieldName)
Deprecated.List<FieldViolation>
getFieldViolations()
Deprecated.List<FieldViolation>
getFieldViolations(String fieldName)
Deprecated.List<ConstraintViolation>
getGeneralViolations()
Deprecated.List<ConstraintViolation>
getViolations()
Get all constraint violations.List<ConstraintViolation>
getViolations(String paramName)
Get a complete list of field violations for a specified parameter.boolean
hasBeanViolation(String name)
Deprecated.boolean
hasBeanViolations()
Deprecated.boolean
hasFieldViolation(String field)
Deprecated.boolean
hasViolation(String paramName)
Whether the validation context has a violation for the given fieldboolean
hasViolations()
Whether the validation context has violations (including field and bean violations)
-
-
-
Method Detail
-
hasViolations
boolean hasViolations()
Whether the validation context has violations (including field and bean violations)- Returns:
- True if it does
-
hasViolation
boolean hasViolation(String paramName)
Whether the validation context has a violation for the given field- Returns:
- True if it does
-
getViolations
List<ConstraintViolation> getViolations()
Get all constraint violations.- Returns:
- The list of all violations.
-
getViolations
List<ConstraintViolation> getViolations(String paramName)
Get a complete list of field violations for a specified parameter.- Returns:
- A List of FieldViolation-objects
-
addViolation
void addViolation(ConstraintViolation constraintViolation)
Add a violation- Parameters:
constraintViolation
- The constraint violation
-
hasFieldViolation
@Deprecated boolean hasFieldViolation(String field)
Deprecated.Whether the validation context has a violation for the given field- Returns:
- True if it does
-
addFieldViolation
@Deprecated void addFieldViolation(String field, ConstraintViolation constraintViolation)
Deprecated.Add a violation to the given field- Parameters:
field
- The field to add the violation toconstraintViolation
- The constraint violation
-
getFieldViolations
@Deprecated List<FieldViolation> getFieldViolations()
Deprecated.Get a complete list of all field violations. This list DOES NOT contain general violations (use getGeneralViolations() instead).- Returns:
- A List of FieldViolation-objects
-
getFieldViolations
@Deprecated List<FieldViolation> getFieldViolations(String fieldName)
Deprecated.Get a complete list of field violations for a specified field. This list DOES NOT contain general violations (use getGeneralViolations() instead).- Returns:
- A List of FieldViolation-objects
-
getGeneralViolations
@Deprecated List<ConstraintViolation> getGeneralViolations()
Deprecated.Get all general constraint violations. This list does not contain any specific field violation (use getFieldViolations() instead).- Returns:
- The list of general violations.
-
addFieldViolation
@Deprecated void addFieldViolation(FieldViolation fieldViolation)
Deprecated.Add a field violation to the list of filed violations.- Parameters:
fieldViolation
-
-
addBeanViolation
@Deprecated void addBeanViolation(FieldViolation fieldViolation)
Deprecated.Add a bean violation. A bean, like a DTO consists of several fields which are validated. Each validation error of a dto-field results in a field-violation for that bean. Note: For now, you can only have one bean in your controller method signature, so this is explicit.- Parameters:
beanName
- maybe the name of your dtofieldViolation
- the FieldViolation consisting of a cinstraintViolation and the fields name
-
hasBeanViolation
@Deprecated boolean hasBeanViolation(String name)
Deprecated.Checks if the validation has bean violation.- Parameters:
name
- Name of the bean.- Returns:
- Whether the named bean has violation.
-
hasBeanViolations
@Deprecated boolean hasBeanViolations()
Deprecated.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.- Returns:
- true if there are any, false if none
-
getBeanViolations
@Deprecated List<FieldViolation> getBeanViolations()
Deprecated.Get all bean validations for that bean. Note: For now, you can only have one bean in your controller method signature, so this is explicit.- Parameters:
beanName
-- Returns:
- A list of field violations
-
getBeanViolations
@Deprecated List<FieldViolation> getBeanViolations(String fieldName)
Deprecated.Get a complete list of bean violations for a specified field. This list DOES NOT contain general violations (use getGeneralViolations() instead).- Returns:
- A List of FieldViolation-objects
-
-