public abstract class FieldValidator extends java.lang.Object
validate(fc.web.forms.FormData, javax.servlet.http.HttpServletRequest)) for various validation strategies. Subclasses are typically specific to both the field type and the type of validation. So for example, the
ValidatorTextwould verify that the specified HTML form element of type "text" has the specified length.
Field level validators differ from
because validation is at the field (per field) level and is
independent of other fields in the form.
Note: Validator objects have state and a particular instance of a validator should only be assigned to one form field. To ensure this, validators take a field reference in their constructors and automatically add themselves to the specified field at construction time. During validation, validators are sequentially called in the order they were added (which implies in the order they were constructed).
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|
Creates a new validator.
|Modifier and Type||Method and Description|
Returns the field associated with this validator.
Validates the field in some fashion.
public FieldValidator(Field field, java.lang.String errorMessage)
field- the field to validate. This validator is added to the field automatically. Subclasses can later retrieve the field for validation.
errorMessage- the error message associated with invalid data See
public abstract boolean validate(FormData fd, HttpServletRequest req)
If there are validation error, stores the error in the formdata and returns false, otherwise returns true
public java.lang.String getErrorMessage()