fc.web.forms
Class FormValidator

java.lang.Object
  extended by fc.web.forms.FormValidator
Direct Known Subclasses:
VConditional, VFilledGroup, VPasswordGroup, VSameText

public abstract class FormValidator
extends Object

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(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 Summary
FormValidator(Form f, String name, String errorMessage)
          Creates a new validator and adds it to the specified form.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FormValidator

public FormValidator(Form f,
                     String name,
                     String errorMessage)
Creates a new validator and adds it to the specified form.

Parameters:
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 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:


getErrorMessage

public String getErrorMessage()

setErrorMessage

public void setErrorMessage(String message)
Sets the error message for this validator -- useful when the error message need to be changed dynamically.


getName

public String getName()

toString

public String toString()
Overrides:
toString in class Object