org.enhydra.barracuda.core.forms
Interface FormValidator

All Known Implementing Classes:
AbstractFormValidator

public interface FormValidator

A FormValidator is designed to validate one or more FormElements within a FormMap, OR a FormMap itself. The real work occurs in the validate() method.

When the validate method is invoked, we start by performing element level validation by invoking the validateFormElement() methods for each of the elements in the form. If that succeeds, we validate the whole map by invoking validateForm() method to validate the form itself. Finally, we invoke any child validators. In this way, a validator is not considered validated until all it's rules plus those for all of it's children have passed muster.

When an invalid condition occurs, typically the developer will throw a ValidationException, which stops the validation process immediately and returns the specified error. There are times, however, where the developer will want to try and validate as many of the rules as possible in order to return all known errors at once. In this case, the developer should throw DeferredValidationExceptions. These are caught internally and added to one master validation exception, which is thrown when the validation process completes.


Method Summary
 String getErrorMessage()
          Get the error message to be used in the event of an error.
 boolean isNull(Object val, FormElement element)
          Check if val passed is null in a consistant manner.
 void setErrorMessage(String ierrorMessage)
          Set the error message to be used in the event of an error.
 void validate(FormElement element, FormMap formMap, boolean deferExceptions)
          Validate a FormElement locally and allow any child validators a chance to validate as well.
 

Method Detail

setErrorMessage

public void setErrorMessage(String ierrorMessage)
Set the error message to be used in the event of an error.

Parameters:
ierrorMessage - the error message to be used in the event of an error

getErrorMessage

public String getErrorMessage()
Get the error message to be used in the event of an error.

Returns:
the error message to be used in the event of an error

validate

public void validate(FormElement element,
                     FormMap formMap,
                     boolean deferExceptions)
              throws ValidationException
Validate a FormElement locally and allow any child validators a chance to validate as well.

Parameters:
element - the form element to be validated (null indicates we want to perform form level validation)
formMap - the map to which the element belongs (sometimes necessary to validate elements by comparing them with other elements)
deferExceptions - do we want to deferValidation exceptions and attempt to validate all elements so that we can process all the exceptions at once
Throws:
ValidationException - if the element is not valid

isNull

public boolean isNull(Object val,
                      FormElement element)
Check if val passed is null in a consistant manner. Most validators should call isNull(val) first thing and return if that is the case. Leave null validation up to NotNullValidator.

Parameters:
val - the value to test for nullness


Copyright © 2003 BarracudaMVC.org All Rights Reserved.