Class ValidatorSupport
java.lang.Object
org.apache.struts2.validator.validators.ValidatorSupport
- All Implemented Interfaces:
ShortCircuitableValidator,Validator
- Direct Known Subclasses:
ExpressionValidator,FieldValidatorSupport
public abstract class ValidatorSupport
extends Object
implements Validator, ShortCircuitableValidator
Abstract implementation of the Validator interface suitable for subclassing.
- Author:
- Jason Carreira, tm_jee, Martin Gilday
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringstatic final Stringprotected Stringprotected ValueStackprotected TextProviderFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddActionError(Object object) protected voidaddFieldError(String propertyName, Object object) Gets the default message used for validation failuresprotected ObjectgetFieldValue(String name, Object object) Return the field value namednamefromobject,objectshould have the appropriate getter/setter.getMessage(Object object) Gets the validation failure message for the given objectGets the resource bundle key used for lookup of validation failure messageString[]Gets the message parameters to be used when parsing i18n messagesGets the validation context usedGets the validator type used (see class javadoc).booleanGets whether this field validator should short circuit the validator queue it's in if validation fails.protected ObjectParseexpressionpassed in against value stack.voidsetDefaultMessage(String message) Sets the default message to use for validation failurevoidsetMessageKey(String key) Sets a resource bundle key to be used for lookup of validation failure messagevoidsetMessageParameters(String[] messageParameters) Sets the message parameters to be used when parsing i18n messagesvoidsetShortCircuit(boolean shortcircuit) Sets whether this field validator should short circuit the validator queue it's in if validation fails.voidsetTextProviderFactory(TextProviderFactory textProviderFactory) voidsetValidatorContext(ValidatorContext validatorContext) This method will be called before validate with a non-null ValidatorContext.voidsetValidatorType(String type) Sets the validator type to use (see class javadoc).voidsetValueStack(ValueStack stack) Sets the value stack to use to resolve values and parameters
-
Field Details
-
EMPTY_STRING
- See Also:
-
defaultMessage
-
messageKey
-
stack
-
textProviderFactory
-
-
Constructor Details
-
ValidatorSupport
public ValidatorSupport()
-
-
Method Details
-
setTextProviderFactory
-
setValueStack
Description copied from interface:ValidatorSets the value stack to use to resolve values and parameters- Specified by:
setValueStackin interfaceValidator- Parameters:
stack- The value stack for the request
-
setDefaultMessage
Description copied from interface:ValidatorSets the default message to use for validation failure- Specified by:
setDefaultMessagein interfaceValidator- Parameters:
message- the default message
-
getDefaultMessage
Description copied from interface:ValidatorGets the default message used for validation failures- Specified by:
getDefaultMessagein interfaceValidator- Returns:
- the default message
-
getMessage
Description copied from interface:ValidatorGets the validation failure message for the given object- Specified by:
getMessagein interfaceValidator- Parameters:
object- object being validated (eg. a domain model object)- Returns:
- the validation failure message
-
setMessageKey
Description copied from interface:ValidatorSets a resource bundle key to be used for lookup of validation failure message- Specified by:
setMessageKeyin interfaceValidator- Parameters:
key- the resource bundle key
-
getMessageKey
Description copied from interface:ValidatorGets the resource bundle key used for lookup of validation failure message- Specified by:
getMessageKeyin interfaceValidator- Returns:
- the resource bundle key
-
getMessageParameters
Description copied from interface:ValidatorGets the message parameters to be used when parsing i18n messages- Specified by:
getMessageParametersin interfaceValidator- Returns:
- the message parameters
-
setMessageParameters
Description copied from interface:ValidatorSets the message parameters to be used when parsing i18n messages- Specified by:
setMessageParametersin interfaceValidator- Parameters:
messageParameters- the message parameters
-
setShortCircuit
public void setShortCircuit(boolean shortcircuit) Description copied from interface:ShortCircuitableValidatorSets whether this field validator should short circuit the validator queue it's in if validation fails.- Specified by:
setShortCircuitin interfaceShortCircuitableValidator- Parameters:
shortcircuit- true if this field validator should short circuit on failure, false otherwise
-
isShortCircuit
public boolean isShortCircuit()Description copied from interface:ShortCircuitableValidatorGets whether this field validator should short circuit the validator queue it's in if validation fails.- Specified by:
isShortCircuitin interfaceShortCircuitableValidator- Returns:
- true if this field validator should short circuit on failure, false otherwise
-
setValidatorContext
Description copied from interface:ValidatorThis method will be called before validate with a non-null ValidatorContext.- Specified by:
setValidatorContextin interfaceValidator- Parameters:
validatorContext- the validation context to use.
-
getValidatorContext
Description copied from interface:ValidatorGets the validation context used- Specified by:
getValidatorContextin interfaceValidator- Returns:
- the validation context
-
setValidatorType
Description copied from interface:ValidatorSets the validator type to use (see class javadoc).- Specified by:
setValidatorTypein interfaceValidator- Parameters:
type- the type to use.
-
getValidatorType
Description copied from interface:ValidatorGets the validator type used (see class javadoc).- Specified by:
getValidatorTypein interfaceValidator- Returns:
- the type used
-
parse
Parseexpressionpassed in against value stack.- Parameters:
expression- an OGNL expressiontype- type to return- Returns:
- Object
-
getFieldValue
Return the field value namednamefromobject,objectshould have the appropriate getter/setter.- Parameters:
name- name of the fieldobject- to search field name on- Returns:
- Object as field value
- Throws:
ValidationException- in case of validation problems
-
addActionError
-
addFieldError
-