public abstract class FormValidator extends Object
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(fc.web.forms.FormData, javax.servlet.http.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 and Description |
---|
FormValidator(Form f,
String name,
String errorMessage)
Creates a new validator and adds it to the specified
form.
|
Modifier and Type | Method and Description |
---|---|
String |
getErrorMessage() |
String |
getName() |
void |
setErrorMessage(String message)
Sets the error message for this validator -- useful when
the error message need to be changed dynamically.
|
String |
toString() |
abstract boolean |
validate(FormData fd,
javax.servlet.http.HttpServletRequest req)
Validates multiple fields together.
|
public FormValidator(Form f, String name, String errorMessage)
errorMessage
- the error message associated with invalid data
See getErrorMessage()
public abstract boolean validate(FormData fd, javax.servlet.http.HttpServletRequest req)
Important notes: Typically, validation should be skipped in the following circumstances:
DependentField
and the
DependentField#shouldValidate
method returns false.public String getErrorMessage()
public void setErrorMessage(String message)