public class DelegatingValidatorContext extends Object implements ValidatorContext
ValidatorContext
interface.Constructor and Description |
---|
DelegatingValidatorContext(Class clazz)
Deprecated.
will be removed, do not use!
|
DelegatingValidatorContext(Object object,
TextProviderFactory textProviderFactory)
Creates a new validation context given an object - usually an Action.
|
DelegatingValidatorContext(ValidationAware validationAware,
TextProvider textProvider,
LocaleProvider localeProvider)
Creates a new validation context given a ValidationAware object, and a text and locale provider.
|
Modifier and Type | Method and Description |
---|---|
void |
addActionError(String anErrorMessage)
Add an Action-level error message to this Action.
|
void |
addActionMessage(String aMessage)
Add an Action-level message to this Action.
|
void |
addFieldError(String fieldName,
String errorMessage)
Add an error message for a given field.
|
Collection<String> |
getActionErrors()
Get the Collection of Action-level error messages for this action.
|
Collection<String> |
getActionMessages()
Get the Collection of Action-level messages for this action.
|
Map<String,List<String>> |
getFieldErrors()
Get the field specific errors associated with this action.
|
String |
getFullFieldName(String fieldName)
Translates a simple field name into a full field name in OGNL syntax.
|
Locale |
getLocale()
Gets the provided locale.
|
String |
getText(String aTextName)
Gets a message based on a message key or if no message is found the provided key
is returned.
|
String |
getText(String aTextName,
List<?> args)
Gets a message based on a key using the supplied args, as defined in
MessageFormat or the provided key if no message is found. |
String |
getText(String aTextName,
String defaultValue)
Gets a message based on a key, or, if the message is not found, a supplied
default value is returned.
|
String |
getText(String key,
String[] args)
Gets a message based on a key using the supplied args, as defined in
MessageFormat , or the provided key if no message is found. |
String |
getText(String aTextName,
String defaultValue,
List<?> args)
Gets a message based on a key using the supplied args, as defined in
MessageFormat , or, if the message is not found, a supplied
default value is returned. |
String |
getText(String key,
String defaultValue,
List<?> args,
ValueStack stack)
Gets a message based on a key using the supplied args, as defined in
MessageFormat , or, if the message is not found, a supplied
default value is returned. |
String |
getText(String aTextName,
String defaultValue,
String obj)
Gets a message based on a key using the supplied obj, as defined in
MessageFormat , or, if the message is not found, a supplied
default value is returned. |
String |
getText(String key,
String defaultValue,
String[] args)
Gets a message based on a key using the supplied args, as defined in
MessageFormat , or, if the message is not found, a supplied
default value is returned. |
String |
getText(String key,
String defaultValue,
String[] args,
ValueStack stack)
Gets a message based on a key using the supplied args, as defined in
MessageFormat , or, if the message is not found, a supplied
default value is returned. |
protected TextProvider |
getTextProvider() |
ResourceBundle |
getTexts()
Get the resource bundle associated with the implementing class (usually an action).
|
ResourceBundle |
getTexts(String aBundleName)
Get the named bundle, such as "com/acme/Foo".
|
protected ValidationAware |
getValidationAware() |
boolean |
hasActionErrors()
Check whether there are any Action-level error messages.
|
boolean |
hasActionMessages()
Checks whether there are any Action-level messages.
|
boolean |
hasErrors()
Checks whether there are any action errors or field errors.
|
boolean |
hasFieldErrors()
Check whether there are any field errors associated with this action.
|
boolean |
hasKey(String key)
Checks if a message key exists.
|
boolean |
isValidLocale(Locale locale)
Validates if provided
Locale is value |
boolean |
isValidLocaleString(String localeStr)
Validates if provided string is a valid
Locale |
protected static LocaleProvider |
makeLocaleProvider(Object object) |
TextProvider |
makeTextProvider(Object object,
TextProviderFactory textProviderFactory) |
protected static ValidationAware |
makeValidationAware(Object object) |
void |
setActionErrors(Collection<String> errorMessages)
Set the Collection of Action-level String error messages.
|
void |
setActionMessages(Collection<String> messages)
Set the Collection of Action-level String messages (not errors).
|
void |
setFieldErrors(Map<String,List<String>> errorMap)
Set the field error map of fieldname (String) to Collection of String error messages.
|
protected void |
setTextProvider(TextProvider textProvider) |
protected void |
setValidationAware(ValidationAware validationAware) |
public DelegatingValidatorContext(ValidationAware validationAware, TextProvider textProvider, LocaleProvider localeProvider)
validationAware
- a validation aware objecttextProvider
- a text providerlocaleProvider
- a local providerpublic DelegatingValidatorContext(Object object, TextProviderFactory textProviderFactory)
object
- the object to use for validation (usually an Action).@Deprecated public DelegatingValidatorContext(Class clazz)
clazz
- the class to initialize the context with.public void setActionErrors(Collection<String> errorMessages)
ValidationAware
setActionErrors
in interface ValidationAware
errorMessages
- Collection of String error messagespublic Collection<String> getActionErrors()
ValidationAware
getActionErrors
in interface ValidationAware
public void setActionMessages(Collection<String> messages)
ValidationAware
setActionMessages
in interface ValidationAware
messages
- Collection of String messages (not errors).public Collection<String> getActionMessages()
ValidationAware
getActionMessages
in interface ValidationAware
public void setFieldErrors(Map<String,List<String>> errorMap)
ValidationAware
setFieldErrors
in interface ValidationAware
errorMap
- field error mappublic Map<String,List<String>> getFieldErrors()
ValidationAware
getFieldErrors
in interface ValidationAware
public String getFullFieldName(String fieldName)
ValidatorContext
getFullFieldName
in interface ValidatorContext
fieldName
- the field name to lookup.public Locale getLocale()
LocaleProvider
getLocale
in interface LocaleProvider
public boolean isValidLocaleString(String localeStr)
LocaleProvider
Locale
isValidLocaleString
in interface LocaleProvider
localeStr
- a String representing locale, e.g. en_ENpublic boolean isValidLocale(Locale locale)
LocaleProvider
Locale
is valueisValidLocale
in interface LocaleProvider
locale
- instance of Locale
to validatepublic boolean hasKey(String key)
TextProvider
hasKey
in interface TextProvider
key
- message key to check forpublic String getText(String aTextName)
TextProvider
getText
in interface TextProvider
aTextName
- the resource bundle key that is to be searched forpublic String getText(String aTextName, String defaultValue)
TextProvider
getText
in interface TextProvider
aTextName
- the resource bundle key that is to be searched fordefaultValue
- the default value which will be returned if no message is foundpublic String getText(String aTextName, String defaultValue, String obj)
TextProvider
MessageFormat
, or, if the message is not found, a supplied
default value is returned.getText
in interface TextProvider
aTextName
- the resource bundle key that is to be searched fordefaultValue
- the default value which will be returned if no message is foundobj
- obj to be used in a MessageFormat
messagepublic String getText(String aTextName, List<?> args)
TextProvider
MessageFormat
or the provided key if no message is found.getText
in interface TextProvider
aTextName
- the resource bundle key that is to be searched forargs
- a list args to be used in a MessageFormat
messagepublic String getText(String key, String[] args)
TextProvider
MessageFormat
, or the provided key if no message is found.getText
in interface TextProvider
key
- the resource bundle key that is to be searched forargs
- an array args to be used in a MessageFormat
messagepublic String getText(String aTextName, String defaultValue, List<?> args)
TextProvider
MessageFormat
, or, if the message is not found, a supplied
default value is returned.getText
in interface TextProvider
aTextName
- the resource bundle key that is to be searched fordefaultValue
- the default value which will be returned if no message is foundargs
- a list args to be used in a MessageFormat
messagepublic String getText(String key, String defaultValue, String[] args)
TextProvider
MessageFormat
, or, if the message is not found, a supplied
default value is returned.getText
in interface TextProvider
key
- the resource bundle key that is to be searched fordefaultValue
- the default value which will be returned if no message is foundargs
- an array args to be used in a MessageFormat
messagepublic ResourceBundle getTexts(String aBundleName)
TextProvider
getTexts
in interface TextProvider
aBundleName
- the name of the resource bundle, such as "com/acme/Foo"
.public String getText(String key, String defaultValue, List<?> args, ValueStack stack)
TextProvider
MessageFormat
, or, if the message is not found, a supplied
default value is returned. Instead of using the value stack in the ActionContext
this version of the getText() method uses the provided value stack.getText
in interface TextProvider
key
- the resource bundle key that is to be searched fordefaultValue
- the default value which will be returned if no message is foundargs
- a list args to be used in a MessageFormat
messagestack
- the value stack to use for finding the textpublic String getText(String key, String defaultValue, String[] args, ValueStack stack)
TextProvider
MessageFormat
, or, if the message is not found, a supplied
default value is returned. Instead of using the value stack in the ActionContext
this version of the getText() method uses the provided value stack.getText
in interface TextProvider
key
- the resource bundle key that is to be searched fordefaultValue
- the default value which will be returned if no message is foundargs
- an array args to be used in a MessageFormat
messagestack
- the value stack to use for finding the textpublic ResourceBundle getTexts()
TextProvider
getTexts
in interface TextProvider
public void addActionError(String anErrorMessage)
ValidationAware
addActionError
in interface ValidationAware
anErrorMessage
- the error messagepublic void addActionMessage(String aMessage)
ValidationAware
addActionMessage
in interface ValidationAware
aMessage
- the messagepublic void addFieldError(String fieldName, String errorMessage)
ValidationAware
addFieldError
in interface ValidationAware
fieldName
- name of fielderrorMessage
- the error messagepublic boolean hasActionErrors()
ValidationAware
hasActionErrors
in interface ValidationAware
public boolean hasActionMessages()
ValidationAware
hasActionMessages
in interface ValidationAware
public boolean hasErrors()
ValidationAware
hasErrors
in interface ValidationAware
(hasActionErrors() || hasFieldErrors())
public boolean hasFieldErrors()
ValidationAware
hasFieldErrors
in interface ValidationAware
public TextProvider makeTextProvider(Object object, TextProviderFactory textProviderFactory)
protected static LocaleProvider makeLocaleProvider(Object object)
protected static ValidationAware makeValidationAware(Object object)
protected void setTextProvider(TextProvider textProvider)
protected TextProvider getTextProvider()
protected void setValidationAware(ValidationAware validationAware)
protected ValidationAware getValidationAware()
Copyright © 2000–2020 Apache Software Foundation. All rights reserved.