Class FormValidator
java.lang.Object
fc.web.forms.FormValidator
- Direct Known Subclasses:
VConditional, VFilledGroup, VPasswordGroup, VSameText
Represents a form level validator that may examine more than
one form field for a grouped/form level validation. Form level
validators differ from
FieldValidator because one may
need to validate a group of fields together.
Examples include address validation where street, city and zip might
need to be verified together (for a valid address) or password
validation where two separate password boxes might need to be
validated (to be identical). Various subclasses implement
concrete code (via validate(FormData, HttpServletRequest)) for various validation
strategies.
Note 1: Validator objects have state and a particular instance of a validator should only be assigned to one form field.
Thread safety: None of the validation classes (like all other form-related classes) are thread safe. Synchronization must be done at a higher level, typically the session level.
-
Constructor Summary
ConstructorsConstructorDescriptionFormValidator(Form f, String name, String errorMessage) Creates a new validator and adds it to the specified form. -
Method Summary
Modifier and TypeMethodDescriptiongetName()voidsetErrorMessage(String message) Sets the error message for this validator -- useful when the error message need to be changed dynamically.toString()abstract booleanValidates multiple fields together.
-
Constructor Details
-
FormValidator
Creates a new validator and adds it to the specified form.- Parameters:
errorMessage- the error message associated with invalid data SeegetErrorMessage()
-
-
Method Details
-
validate
Validates multiple fields together. Note, implementations need not call the validator for each field if that field also has a field level validator (since each field is individually validated by the form). Implementations should validate multiple fields to see if they make sense when analysed as a whole.Important notes: Typically, validation should be skipped in the following circumstances:
- The field is disabled.
- The field is an instance of
DependentFieldand themethod returns false.invalid reference
DependentField#shouldValidate
- Returns:
- true is validation succeeded, false otherwise
-
getErrorMessage
-
setErrorMessage
Sets the error message for this validator -- useful when the error message need to be changed dynamically. -
getName
-
toString
-