org.liquidsite.core.web
Class FormValidator

java.lang.Object
  extended byorg.liquidsite.core.web.FormValidator

public class FormValidator
extends java.lang.Object

A form field validator. This class contains methods for checking request input parameters in various ways.


Constructor Summary
FormValidator()
          Creates a new form field validator.
 
Method Summary
 void addCharacterConstraint(java.lang.String field, java.lang.String chars, java.lang.String message)
          Adds a form field character constraint.
 void addDateConstraint(java.lang.String field, java.text.DateFormat format, java.lang.String message)
          Adds a form field date constraint.
 void addLengthConstraint(java.lang.String field, int min, int max, java.lang.String message)
          Adds a form field length constraint.
 void addRequiredConstraint(java.lang.String field, java.lang.String message)
          Adds a form field required constraint.
 void validate(Request request)
          Validates the parameters in a request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormValidator

public FormValidator()
Creates a new form field validator.

Method Detail

addRequiredConstraint

public void addRequiredConstraint(java.lang.String field,
                                  java.lang.String message)
Adds a form field required constraint. This will check that the specified form field isn't empty or null.

Parameters:
field - the field name
message - the message on error

addLengthConstraint

public void addLengthConstraint(java.lang.String field,
                                int min,
                                int max,
                                java.lang.String message)
Adds a form field length constraint. This will check that the length of the specified form field is in the range.

Parameters:
field - the field name
min - the minimum length
max - the maximum length, or -1 for infinite
message - the message on error

addCharacterConstraint

public void addCharacterConstraint(java.lang.String field,
                                   java.lang.String chars,
                                   java.lang.String message)
Adds a form field character constraint. This will check that the specified form field only contains characters from the specified set.

Parameters:
field - the field name
chars - the character set to allow
message - the message on error

addDateConstraint

public void addDateConstraint(java.lang.String field,
                              java.text.DateFormat format,
                              java.lang.String message)
Adds a form field date constraint. This will check that the specified form field is parseable with the date formatter.

Parameters:
field - the field name
format - the date format to allow
message - the message on error

validate

public void validate(Request request)
              throws FormValidationException
Validates the parameters in a request. The constraints will be checked in the same order as they were added to this validator.

Parameters:
request - the form request
Throws:
FormValidationException - if the form validation failed