com.opensymphony.xwork.validator.validators
Class VisitorFieldValidator
java.lang.Object
com.opensymphony.xwork.validator.validators.ValidatorSupport
com.opensymphony.xwork.validator.validators.FieldValidatorSupport
com.opensymphony.xwork.validator.validators.VisitorFieldValidator
- All Implemented Interfaces:
- FieldValidator, ShortCircuitableValidator, Validator
public class VisitorFieldValidator
- extends FieldValidatorSupport
The VisitorFieldValidator allows you to forward validation to object
properties of your action using the object's own validation files. This
allows you to use the ModelDriven development pattern and manage your
validations for your models in one place, where they belong, next to your
model classes. The VisitorFieldValidator can handle either simple Object
properties, Collections of Objects, or Arrays.
- fieldName - field name if plain-validator syntax is used, not needed if field-validator syntax is used
- context - the context of which validation should take place. If it is not used, will default to the name of the action. Optional
- appendPrefix - (true/false) determine if prefix is to be added to field. Optional
<validators>
<!-- Plain Validator Syntax -->
<validator type="visitor">
<param name="fieldName">user</param>
<param name="context">myContext</param>
<param name="appendPrefix">true</param>
</validator>
<!-- Field Validator Syntax -->
<field name="user">
<field-validator type="visitor">
<param name="context">myContext</param>
<param name="appendPrefix">true</param>
</field-validator>
</field>
</validators>
In the example above, if the acion's getUser() method return User object, WebWork
will look for User-myContext-validation.xml for the validators. Since appednPrefix is true,
every field name will be prefixed with 'user' such that if the actual field name for 'name' is
'user.name'
- Version:
- $Date: 2007-11-22 08:52:41 -0600 (Thu, 22 Nov 2007) $ $Id: VisitorFieldValidator.java 1677 2007-11-22 14:52:41Z tm_jee $
- Author:
- Jason Carreira, Rainer Hermanns
Method Summary |
String |
getContext()
|
boolean |
isAppendPrefix()
Flags whether the field name of this field validator should be prepended to the field name of
the visited field to determine the full field name when an error occurs. |
void |
setAppendPrefix(boolean appendPrefix)
Sets whether the field name of this field validator should be prepended to the field name of
the visited field to determine the full field name when an error occurs. |
void |
setContext(String context)
|
void |
validate(Object object)
The validation implementation must guarantee that setValidatorContext will
be called with a non-null ValidatorContext before validate is called. |
Methods inherited from class com.opensymphony.xwork.validator.validators.ValidatorSupport |
addActionError, addFieldError, conditionalParse, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getMessageParameters, getParse, getValidatorContext, isShortCircuit, setDefaultMessage, setMessageKey, setMessageParameters, setParse, setShortCircuit, setValidatorContext |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
VisitorFieldValidator
public VisitorFieldValidator()
setAppendPrefix
public void setAppendPrefix(boolean appendPrefix)
- Sets whether the field name of this field validator should be prepended to the field name of
the visited field to determine the full field name when an error occurs. The default is
true.
isAppendPrefix
public boolean isAppendPrefix()
- Flags whether the field name of this field validator should be prepended to the field name of
the visited field to determine the full field name when an error occurs. The default is
true.
setContext
public void setContext(String context)
getContext
public String getContext()
validate
public void validate(Object object)
throws ValidationException
- Description copied from interface:
Validator
- The validation implementation must guarantee that setValidatorContext will
be called with a non-null ValidatorContext before validate is called.
- Throws:
ValidationException