Class VisitorFieldValidator
java.lang.Object
org.apache.struts2.validator.validators.ValidatorSupport
org.apache.struts2.validator.validators.FieldValidatorSupport
org.apache.struts2.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.
- 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. Optional
- appendPrefix - the prefix 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 action'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'
- Author:
- Jason Carreira, Rainer Hermanns
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.struts2.validator.validators.FieldValidatorSupport
currentValue, fieldName, type
Fields inherited from class org.apache.struts2.validator.validators.ValidatorSupport
defaultMessage, EMPTY_STRING, messageKey, stack, textProviderFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
void
setAppendPrefix
(boolean appendPrefix) void
setContext
(String context) void
The validation implementation must guarantee that setValidatorContext will be called with a non-null ValidatorContext before validate is called.Methods inherited from class org.apache.struts2.validator.validators.FieldValidatorSupport
getCurrentValue, getFieldName, getValidatorType, setFieldName, setValidatorType
Methods inherited from class org.apache.struts2.validator.validators.ValidatorSupport
addActionError, addFieldError, getDefaultMessage, getFieldValue, getMessage, getMessageKey, getMessageParameters, getValidatorContext, isShortCircuit, parse, setDefaultMessage, setMessageKey, setMessageParameters, setShortCircuit, setTextProviderFactory, setValidatorContext, setValueStack
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.struts2.validator.Validator
getDefaultMessage, getMessage, getMessageKey, getMessageParameters, getValidatorContext, setDefaultMessage, setMessageKey, setMessageParameters, setValidatorContext, setValueStack
-
Constructor Details
-
VisitorFieldValidator
public VisitorFieldValidator()
-
-
Method Details
-
setActionValidatorManager
-
setAppendPrefix
public void setAppendPrefix(boolean appendPrefix) - Parameters:
appendPrefix
- 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()- Returns:
- 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
-
getContext
-
validate
Description copied from interface:Validator
The validation implementation must guarantee that setValidatorContext will be called with a non-null ValidatorContext before validate is called.- Parameters:
object
- the object to be validated.- Throws:
ValidationException
- is thrown if there is validation error(s).
-