public abstract class FieldValidator extends 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 ValidatorText
would verify that the
specified HTML form element of type "text" has the specified
length.
Field level validators differ from FormValidator
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 |
---|
FieldValidator(Field field,
String errorMessage)
Creates a new validator.
|
Modifier and Type | Method and Description |
---|---|
String |
getErrorMessage() |
Field |
getField()
Returns the field associated with this validator.
|
abstract boolean |
validate(FormData fd,
javax.servlet.http.HttpServletRequest req)
Validates the field in some fashion.
|
public FieldValidator(Field field, 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 getErrorMessage()
public abstract boolean validate(FormData fd, javax.servlet.http.HttpServletRequest req)
If there are validation error, stores the error in the formdata and returns false, otherwise returns true
public String getErrorMessage()