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 String
static final String
protected String
protected ValueStack
protected TextProviderFactory
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addActionError
(Object object) protected void
addFieldError
(String propertyName, Object object) Gets the default message used for validation failuresprotected Object
getFieldValue
(String name, Object object) Return the field value namedname
fromobject
,object
should 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).boolean
Gets whether this field validator should short circuit the validator queue it's in if validation fails.protected Object
Parseexpression
passed in against value stack.void
setDefaultMessage
(String message) Sets the default message to use for validation failurevoid
setMessageKey
(String key) Sets a resource bundle key to be used for lookup of validation failure messagevoid
setMessageParameters
(String[] messageParameters) Sets the message parameters to be used when parsing i18n messagesvoid
setShortCircuit
(boolean shortcircuit) Sets whether this field validator should short circuit the validator queue it's in if validation fails.void
setTextProviderFactory
(TextProviderFactory textProviderFactory) void
setValidatorContext
(ValidatorContext validatorContext) This method will be called before validate with a non-null ValidatorContext.void
setValidatorType
(String type) Sets the validator type to use (see class javadoc).void
setValueStack
(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:Validator
Sets the value stack to use to resolve values and parameters- Specified by:
setValueStack
in interfaceValidator
- Parameters:
stack
- The value stack for the request
-
setDefaultMessage
Description copied from interface:Validator
Sets the default message to use for validation failure- Specified by:
setDefaultMessage
in interfaceValidator
- Parameters:
message
- the default message
-
getDefaultMessage
Description copied from interface:Validator
Gets the default message used for validation failures- Specified by:
getDefaultMessage
in interfaceValidator
- Returns:
- the default message
-
getMessage
Description copied from interface:Validator
Gets the validation failure message for the given object- Specified by:
getMessage
in interfaceValidator
- Parameters:
object
- object being validated (eg. a domain model object)- Returns:
- the validation failure message
-
setMessageKey
Description copied from interface:Validator
Sets a resource bundle key to be used for lookup of validation failure message- Specified by:
setMessageKey
in interfaceValidator
- Parameters:
key
- the resource bundle key
-
getMessageKey
Description copied from interface:Validator
Gets the resource bundle key used for lookup of validation failure message- Specified by:
getMessageKey
in interfaceValidator
- Returns:
- the resource bundle key
-
getMessageParameters
Description copied from interface:Validator
Gets the message parameters to be used when parsing i18n messages- Specified by:
getMessageParameters
in interfaceValidator
- Returns:
- the message parameters
-
setMessageParameters
Description copied from interface:Validator
Sets the message parameters to be used when parsing i18n messages- Specified by:
setMessageParameters
in interfaceValidator
- Parameters:
messageParameters
- the message parameters
-
setShortCircuit
public void setShortCircuit(boolean shortcircuit) Description copied from interface:ShortCircuitableValidator
Sets whether this field validator should short circuit the validator queue it's in if validation fails.- Specified by:
setShortCircuit
in interfaceShortCircuitableValidator
- Parameters:
shortcircuit
- true if this field validator should short circuit on failure, false otherwise
-
isShortCircuit
public boolean isShortCircuit()Description copied from interface:ShortCircuitableValidator
Gets whether this field validator should short circuit the validator queue it's in if validation fails.- Specified by:
isShortCircuit
in interfaceShortCircuitableValidator
- Returns:
- true if this field validator should short circuit on failure, false otherwise
-
setValidatorContext
Description copied from interface:Validator
This method will be called before validate with a non-null ValidatorContext.- Specified by:
setValidatorContext
in interfaceValidator
- Parameters:
validatorContext
- the validation context to use.
-
getValidatorContext
Description copied from interface:Validator
Gets the validation context used- Specified by:
getValidatorContext
in interfaceValidator
- Returns:
- the validation context
-
setValidatorType
Description copied from interface:Validator
Sets the validator type to use (see class javadoc).- Specified by:
setValidatorType
in interfaceValidator
- Parameters:
type
- the type to use.
-
getValidatorType
Description copied from interface:Validator
Gets the validator type used (see class javadoc).- Specified by:
getValidatorType
in interfaceValidator
- Returns:
- the type used
-
parse
Parseexpression
passed in against value stack.- Parameters:
expression
- an OGNL expressiontype
- type to return- Returns:
- Object
-
getFieldValue
Return the field value namedname
fromobject
,object
should 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
-