|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface Validated
This interface defines methods for bean-centric data validation.
Validation is bound to subjects that have distinct names. Each subject
corresponds to a different variable, for example a property of a bean. When
a subject is found to be invalid, a corresponding instance of
ValidationError has to be registered.
ValidationErrors indicate in detail why a
Validated object doesn't contain valid data. They should be
stored internally and can be manipulated by other classes that are able to
work with Validated objects. This makes it possible to collect
errors incrementally in one central place and to allow each component in a
system to perform its own part of the validation.
A Validated object has a validate()
method which should be used to perform mandatory validation on subjects and
data that the object itself knows about. This validation has to perform all
checks that guarantee a coherent internal state of the data. Note that this
method should not reset the validation, but instead add new validation
errors to an already existing collection.
Since it's possible that subjects generate multiple
ValidationErrors, it's possible to limit their number and only
store the first error that occurs for a particular subject.
ValidationError,
ValidationContext| Method Summary | |
|---|---|
void |
addRule(ValidationRule rule)
Adds a new validation rule. |
void |
addValidationError(ValidationError error)
Add a new validation error explicitly to the collection of already existing errors. |
int |
countValidationErrors()
Counts the number of stored ValidationErrors. |
List<ValidationRule> |
getRules()
Retrieves that validation rules that have been registered. |
List<String> |
getValidatedSubjects()
Returns the list of subjects that this object is able to validate internally through the validate() method. |
Set<ValidationError> |
getValidationErrors()
Returns a set with all the stored ValidationErrors. |
boolean |
isSubjectValid(String subject)
Checks if a subject is valid. |
void |
limitSubjectErrors(String subject)
Limits the number of errors for a particular subject so that maximum one ValidationError can be stored for it. |
void |
makeErrorValid(String identifier,
String subject)
Makes errors for a particular subject and identifier valid. |
void |
makeSubjectValid(String subject)
Makes a subject valid. |
void |
provideValidatedBean(Validated bean)
Provide the bean instance that will be validated. |
void |
replaceValidationErrors(Set<ValidationError> errors)
Replaces the stored ValidationErrors with a new set of
errors. |
void |
resetValidation()
Resets the validation by removing all validation errors that are currently present. |
Validated |
retrieveValidatedBean()
Retrieves the bean instance that will be validated. |
void |
unlimitSubjectErrors(String subject)
Unlimits the number of errors for a particular subject so that any number of ValidationErrors can be stored for it. |
boolean |
validate()
Validates the internal subjects. |
boolean |
validate(ValidationContext context)
Validates the internal subjects and also validates the bean within the provided ValidationContext |
| Method Detail |
|---|
boolean validate()
This method is not suppossed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.
true if no validation errors are present after the
validation; or
false if validation errors are available.
validate(ValidationContext),
resetValidation()boolean validate(ValidationContext context)
ValidationContext
This method is not suppossed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.
context - the ValidationContext in which this bean
instance will be additionally validated
true if no validation errors are present after the
validation; or
false if validation errors are available.
validate(),
resetValidation()void addRule(ValidationRule rule)
Adds a new validation rule.
The collection of rules is what is supposed to perform the validation, though any other additional method could be used. At least those rules that have been registered will be evaluated.
rule - the rule that will be addedvalidate(),
getRules()List<ValidationRule> getRules()
validate(),
addRule(com.uwyn.rife.site.ValidationRule)void resetValidation()
Resets the validation by removing all validation errors that are currently present.
This method is typically used to start a new validation from scratch or to re-validate until all errors have been solved.
validate()void addValidationError(ValidationError error)
Note that this method should respect subjects with a limited error amount and only store the first error for these subjects.
error - the ValidationError to addlimitSubjectErrors(String),
unlimitSubjectErrors(String)Set<ValidationError> getValidationErrors()
ValidationErrors.
Set instance with all the stored
ValidationErrors. Note that when no errors are available
an empty set is returned, not null.int countValidationErrors()
ValidationErrors.
ValidationErrors.void replaceValidationErrors(Set<ValidationError> errors)
ValidationErrors with a new set of
errors.
errors - the Set instance that contains all the
ValidationErrors that have to be stored.void limitSubjectErrors(String subject)
ValidationError can be stored for it.
subject - the name of the subject that has to be limited.void unlimitSubjectErrors(String subject)
ValidationErrors can be stored for it.
subject - the name of the subject that has to be unlimited.List<String> getValidatedSubjects()
validate() method.
boolean isSubjectValid(String subject)
This is determined by verifying if there are
ValidationErrors present for it. This method will thus not
execute a validation action.
subject - the name of the subject that has to be checked.
true when no errors could be found for the
subject; or
false when errors are present for the subject.
validate()
void makeErrorValid(String identifier,
String subject)
This is done by removing all ValidationErrors that are
stored with this identifier and subject.
identifier - the name of the error identifier that has to be madesubject - the name of the subject that has to be made valid.
valid.void makeSubjectValid(String subject)
This is done by removing all ValidationErrors that are
stored for it.
subject - the name of the subject that has to be made valid.void provideValidatedBean(Validated bean)
By default 'this' will be used.
bean - the bean instance that will be validatedValidated retrieveValidatedBean()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||