com.townleyenterprises.validator
Class BasicFormValidator

java.lang.Object
  extended bycom.townleyenterprises.validator.BasicFormValidator
All Implemented Interfaces:
FormValidator, java.io.Serializable

public class BasicFormValidator
extends java.lang.Object
implements FormValidator

This class is a bean which provides a basic implementation of a form validator which will perform the validations in the correct order.

Since:
3.0
Version:
$Id: BasicFormValidator.java,v 1.2 2004/08/11 16:21:06 atownley Exp $
Author:
Andrew S. Townley
See Also:
Serialized Form

Constructor Summary
BasicFormValidator()
          Basic constructor
 
Method Summary
 void addFieldSetValidator(FieldSetValidator validator)
          This method is used to add a new field set validator
 void addFieldValidator(java.lang.String name, FieldValidator validator)
          This method is used to add a new validator for a specific field of the form.
 void addValidationListener(ValidationListener listener)
           
 boolean getAbortOnFailure()
          This method is used to determine the mode of the form validator.
 FieldSetValidator[] getFieldSetValidators()
          This method returns the currently configured field set validators as an array.
 FieldValidator[] getFieldValidators()
          This method returns the currently configured field validators as an array.
 ValidationListener[] getValidationListeners()
           
 void removeFieldSetValidator(FieldSetValidator validator)
          This method is used to remove a new field set validator
 void removeFieldValidator(FieldValidator validator)
          This method is used to remove a specific validator instance.
 void removeValidationListener(ValidationListener listener)
           
 void setAbortOnFailure(boolean val)
          This method is used to set the validation mode of the form.
 void validate(Form form)
          This method simply deferrs to the validate(Form,Locale) method.
 void validate(Form form, java.util.Locale locale)
          This method performs the validations in the default order according to the order specified in the interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicFormValidator

public BasicFormValidator()
Basic constructor

Method Detail

getAbortOnFailure

public boolean getAbortOnFailure()
This method is used to determine the mode of the form validator. If it returns false, the validator will attempt to perform all of the registered validations once and notify the listeners of any failures. If it returns true, the validation operation will stop after the first validation failure.

Specified by:
getAbortOnFailure in interface FormValidator
Returns:
false if all fields will be validated; true if not

setAbortOnFailure

public void setAbortOnFailure(boolean val)
This method is used to set the validation mode of the form. Two modes are supported: the first will validate all of the fields on the form (the default), and the second will only validate until the first validation failure occurs.

Specified by:
setAbortOnFailure in interface FormValidator
Parameters:
val - the value of the flag

validate

public void validate(Form form)
              throws java.lang.Exception
This method simply deferrs to the validate(Form,Locale) method.

Specified by:
validate in interface FormValidator
Parameters:
form - the form to validate
Throws:
java.lang.Exception - if any of the validations fail

validate

public void validate(Form form,
                     java.util.Locale locale)
              throws java.lang.Exception
This method performs the validations in the default order according to the order specified in the interface. If any of the child validators fail (regardless of the setting of the abortOnFailure property, this method throws an exception.

Specified by:
validate in interface FormValidator
Parameters:
form - the form to validate
locale - the specific locale to use
Throws:
java.lang.Exception - if any of the validations fail

addFieldValidator

public void addFieldValidator(java.lang.String name,
                              FieldValidator validator)
Description copied from interface: FormValidator
This method is used to add a new validator for a specific field of the form.

Specified by:
addFieldValidator in interface FormValidator
Parameters:
name - the field name
validator - the validator instance

removeFieldValidator

public void removeFieldValidator(FieldValidator validator)
Description copied from interface: FormValidator
This method is used to remove a specific validator instance.

Specified by:
removeFieldValidator in interface FormValidator
Parameters:
validator - the validator to remove

addFieldSetValidator

public void addFieldSetValidator(FieldSetValidator validator)
Description copied from interface: FormValidator
This method is used to add a new field set validator

Specified by:
addFieldSetValidator in interface FormValidator
Parameters:
validator - the validator to add

removeFieldSetValidator

public void removeFieldSetValidator(FieldSetValidator validator)
Description copied from interface: FormValidator
This method is used to remove a new field set validator

Specified by:
removeFieldSetValidator in interface FormValidator
Parameters:
validator - the validator to remove

getFieldValidators

public FieldValidator[] getFieldValidators()
Description copied from interface: FormValidator
This method returns the currently configured field validators as an array.

Specified by:
getFieldValidators in interface FormValidator

getFieldSetValidators

public FieldSetValidator[] getFieldSetValidators()
Description copied from interface: FormValidator
This method returns the currently configured field set validators as an array.

Specified by:
getFieldSetValidators in interface FormValidator

addValidationListener

public void addValidationListener(ValidationListener listener)
Specified by:
addValidationListener in interface FormValidator

removeValidationListener

public void removeValidationListener(ValidationListener listener)
Specified by:
removeValidationListener in interface FormValidator

getValidationListeners

public ValidationListener[] getValidationListeners()
Specified by:
getValidationListeners in interface FormValidator


Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.