|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.enhydra.barracuda.core.forms.AbstractFormValidator
org.enhydra.barracuda.core.forms.DefaultFormValidator
This class provides the default implementation of 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. A validator is also capable of containing other validators, which makes it very easy to create a complex set of validation logic by assembling a "master" validator from a set of simpler validators.
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.
In typical usage the developer would extend this class to override one of the three validateFormElement methods. FormValidators can also act as containers for other FormValidators, thereby allowing the developer to dynamically assemble complex validators from simpler validator objects.
Field Summary | |
protected static org.apache.log4j.Logger |
localLogger
|
protected List |
validators
|
Constructor Summary | |
DefaultFormValidator()
Public noargs constructor (errorMessage defaults to null) |
|
DefaultFormValidator(String ierrorMessage)
Public constructor with a default errorMessage to be dispatched when an invalid state occurs. |
Method Summary | |
void |
addValidator(FormValidator validator)
Add a child validator |
List |
getValidators()
Get a list of all child validators |
void |
removeValidator(FormValidator validator)
Remove a child validator |
void |
validate(FormElement element,
FormMap map,
boolean deferExceptions)
Validate a FormElement locally and allow any child validators a chance to validate as well. |
void |
validateForm(FormMap map,
boolean deferExceptions)
Validate an entire FormMap. |
void |
validateFormElement(Object val,
FormElement element,
boolean deferExceptions)
Validate a FormElement. |
void |
validateFormElement(Object val,
FormElement element,
FormMap map,
boolean deferExceptions)
Validate a FormElement. |
Methods inherited from class org.enhydra.barracuda.core.forms.AbstractFormValidator |
generateException, getErrorMessage, isNull, setErrorMessage |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final org.apache.log4j.Logger localLogger
protected List validators
Constructor Detail |
public DefaultFormValidator()
public DefaultFormValidator(String ierrorMessage)
ierrorMessage
- the default error message for this validatorMethod Detail |
public void addValidator(FormValidator validator)
validator
- the child validator to be addedpublic void removeValidator(FormValidator validator)
validator
- the child validator to be removedpublic List getValidators()
public void validate(FormElement element, FormMap map, boolean deferExceptions) throws ValidationException
element
- the form element to be validated (null indicates
we want to perform form level validation)map
- 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
ValidationException
- if the element is not validpublic void validateForm(FormMap map, boolean deferExceptions) throws ValidationException
map
- the map to be validateddeferExceptions
- do we want to deferValidation exceptions
and attempt to validate all elements so that we can process
all the exceptions at once
ValidationException
- if the element is not validpublic void validateFormElement(Object val, FormElement element, boolean deferExceptions) throws ValidationException
val
- the actual value to be validatedelement
- the form element that contains the val
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
ValidationException
- if the element is not validpublic void validateFormElement(Object val, FormElement element, FormMap map, boolean deferExceptions) throws ValidationException
val
- the actual value to be validatedelement
- the form element that contains the valmap
- 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
ValidationException
- if the element is not valid
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |