fc.web.forms
Class FieldValidator

java.lang.Object
  extended by fc.web.forms.FieldValidator
Direct Known Subclasses:
VDate, VEmail, VFilled, VSelectValue, VText, VTime

public abstract class FieldValidator
extends Object

Represents a form field validator. Various subclasses implement concrete code (via 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 Summary
FieldValidator(Field field, String errorMessage)
          Creates a new validator.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FieldValidator

public FieldValidator(Field field,
                      String errorMessage)
Creates a new validator.

Parameters:
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()
Method Detail

validate

public abstract boolean validate(FormData fd,
                                 javax.servlet.http.HttpServletRequest req)
Validates the field in some fashion.

If there are validation error, stores the error in the formdata and returns false, otherwise returns true


getErrorMessage

public String getErrorMessage()

getField

public Field getField()
Returns the field associated with this validator.