Save This Page
Home » xwork-2.1.1-src » com.opensymphony.xwork2.validator.validators » [javadoc | source]
com.opensymphony.xwork2.validator.validators
public class: VisitorFieldValidator [javadoc | source]
java.lang.Object
   com.opensymphony.xwork2.validator.validators.ValidatorSupport
      com.opensymphony.xwork2.validator.validators.FieldValidatorSupport
         com.opensymphony.xwork2.validator.validators.VisitorFieldValidator

All Implemented Interfaces:
    FieldValidator, ShortCircuitableValidator, Validator

Direct Known Subclasses:
    ConditionalVisitorFieldValidator

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.


<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, XWork 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'

Nested Class Summary:
public static class  VisitorFieldValidator.AppendingValidatorContext   
Fields inherited from com.opensymphony.xwork2.validator.validators.ValidatorSupport:
log,  defaultMessage,  messageKey
Method from com.opensymphony.xwork2.validator.validators.VisitorFieldValidator Summary:
getContext,   isAppendPrefix,   setActionValidatorManager,   setAppendPrefix,   setContext,   validate
Methods from com.opensymphony.xwork2.validator.validators.FieldValidatorSupport:
getFieldName,   getValidatorType,   setFieldName,   setValidatorType
Methods from com.opensymphony.xwork2.validator.validators.ValidatorSupport:
addActionError,   addFieldError,   conditionalParse,   getDefaultMessage,   getFieldValue,   getMessage,   getMessageKey,   getParse,   getValidatorContext,   getValidatorType,   isShortCircuit,   setDefaultMessage,   setMessageKey,   setParse,   setShortCircuit,   setValidatorContext,   setValidatorType,   setValueStack
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.opensymphony.xwork2.validator.validators.VisitorFieldValidator Detail:
 public String getContext() 
 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.
 public  void setActionValidatorManager(ActionValidatorManager mgr) 
 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.
 public  void setContext(String context) 
 public  void validate(Object object) throws ValidationException