Class FieldValidator

java.lang.Object
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(FormData, HttpServletRequest)) for various validation strategies. Subclasses are typically specific to both the field type and the type of validation. So for example, the
invalid reference
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 Details

    • 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 Details

    • validate

      public abstract boolean validate(FormData fd, jakarta.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

    • getField

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