Package org.apache.struts2
Class ActionSupport
java.lang.Object
org.apache.struts2.ActionSupport
- All Implemented Interfaces:
- Serializable,- Action,- ValidationAware,- LocaleProvider,- TextProvider,- Validateable
- Direct Known Subclasses:
- CspReportAction,- DefaultActionSupport
public class ActionSupport
extends Object
implements Action, Validateable, ValidationAware, TextProvider, LocaleProvider, Serializable
Provides a default implementation for the most common actions.
 See the documentation for all the interfaces this class implements for more detailed information.
- See Also:
- 
Field SummaryFields
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddActionError(String anErrorMessage) Add an Action-level error message to this Action.voidaddActionMessage(String aMessage) Add an Action-level message to this Action.voidaddFieldError(String fieldName, String errorMessage) Add an error message for a given field.voidClears action errors.voidClears all errors.voidClears all errors and messages.voidClears field errors.voidClears messages.clone()execute()A default implementation that does nothing an returns "success".Get the Collection of Action-level error messages for this action.Get the Collection of Action-level messages for this action.protected ContainerTODO: This a temporary solution, maybe we should consider stop injecting container into beansGet the field specific errors associated with this action.getFormatted(String key, String expr) Dedicated method to support I10N and conversion errorsGets the provided locale.protected LocaleProviderGets a message based on a message key or if no message is found the provided key is returned.Gets a message based on a key, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormat, or the provided key if no message is found.Gets a message based on a key using the supplied obj, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.getText(String key, String defaultValue, String[] args, ValueStack stack) Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.getText(String key, String defaultValue, List<?> args, ValueStack stack) Gets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.Gets a message based on a key using the supplied args, as defined inMessageFormator the provided key if no message is found.protected TextProviderIf called first time it will createTextProviderFactory, inject dependency (ifContaineris accesible) into in, then will create newTextProviderand store it in a field for future references and at the returns reference to that fieldgetTexts()Get the resource bundle associated with the implementing class (usually an action).Get the named bundle, such as "com/acme/Foo".booleanCheck whether there are any Action-level error messages.booleanChecks whether there are any Action-level messages.booleanChecks whether there are any action errors or field errors.booleanCheck whether there are any field errors associated with this action.booleanChecks if a message key exists.input()booleanisValidLocale(Locale locale) Validates if providedLocaleis valuebooleanisValidLocaleString(String localeStr) Validates if provided string is a validLocalevoidStops the action invocation immediately (by throwing a PauseException) and causes the action invocation to return the specified result, such asAction.SUCCESS,Action.INPUT, etc.voidsetActionErrors(Collection<String> errorMessages) Set the Collection of Action-level String error messages.voidsetActionMessages(Collection<String> messages) Set the Collection of Action-level String messages (not errors).voidsetContainer(Container container) voidsetFieldErrors(Map<String, List<String>> errorMap) Set the field error map of fieldname (String) to Collection of String error messages.Tries to convert provided locale string intoLocaleor returns nullvoidvalidate()A default implementation that validates nothing.
- 
Field Details- 
container
 
- 
- 
Constructor Details- 
ActionSupportpublic ActionSupport()
 
- 
- 
Method Details- 
setActionErrorsDescription copied from interface:ValidationAwareSet the Collection of Action-level String error messages.- Specified by:
- setActionErrorsin interface- ValidationAware
- Parameters:
- errorMessages- Collection of String error messages
 
- 
getActionErrorsDescription copied from interface:ValidationAwareGet the Collection of Action-level error messages for this action. Error messages should not be added directly here, as implementations are free to return a new Collection or an Unmodifiable Collection.- Specified by:
- getActionErrorsin interface- ValidationAware
- Returns:
- Collection of String error messages
 
- 
setActionMessagesDescription copied from interface:ValidationAwareSet the Collection of Action-level String messages (not errors).- Specified by:
- setActionMessagesin interface- ValidationAware
- Parameters:
- messages- Collection of String messages (not errors).
 
- 
getActionMessagesDescription copied from interface:ValidationAwareGet the Collection of Action-level messages for this action. Messages should not be added directly here, as implementations are free to return a new Collection or an Unmodifiable Collection.- Specified by:
- getActionMessagesin interface- ValidationAware
- Returns:
- Collection of String messages
 
- 
setFieldErrorsDescription copied from interface:ValidationAwareSet the field error map of fieldname (String) to Collection of String error messages.- Specified by:
- setFieldErrorsin interface- ValidationAware
- Parameters:
- errorMap- field error map
 
- 
getFieldErrorsDescription copied from interface:ValidationAwareGet the field specific errors associated with this action. Error messages should not be added directly here, as implementations are free to return a new Collection or an Unmodifiable Collection.- Specified by:
- getFieldErrorsin interface- ValidationAware
- Returns:
- Map with errors mapped from fieldname (String) to Collection of String error messages
 
- 
getLocaleDescription copied from interface:LocaleProviderGets the provided locale.- Specified by:
- getLocalein interface- LocaleProvider
- Returns:
- the locale.
 
- 
isValidLocaleStringDescription copied from interface:LocaleProviderValidates if provided string is a validLocale- Specified by:
- isValidLocaleStringin interface- LocaleProvider
- Parameters:
- localeStr- a String representing locale, e.g. en_EN
- Returns:
- true if valid
 
- 
isValidLocaleDescription copied from interface:LocaleProviderValidates if providedLocaleis value- Specified by:
- isValidLocalein interface- LocaleProvider
- Parameters:
- locale- instance of- Localeto validate
- Returns:
- true if valid
 
- 
toLocaleDescription copied from interface:LocaleProviderTries to convert provided locale string intoLocaleor returns null- Specified by:
- toLocalein interface- LocaleProvider
- Parameters:
- localeStr- a String representing locale, e.g.: en_EN
- Returns:
- instance of Localeor null
 
- 
hasKeyDescription copied from interface:TextProviderChecks if a message key exists.- Specified by:
- hasKeyin interface- TextProvider
- Parameters:
- key- message key to check for
- Returns:
- boolean true if key exists, false otherwise.
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a message key or if no message is found the provided key is returned.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- aTextName- the resource bundle key that is to be searched for
- Returns:
- the message as found in the resource bundle, or the provided key if none is found.
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key, or, if the message is not found, a supplied default value is returned.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- aTextName- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key using the supplied obj, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- aTextName- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- obj- obj to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key using the supplied args, as defined inMessageFormator the provided key if no message is found.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- aTextName- the resource bundle key that is to be searched for
- args- a list args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or the provided key if none is found.
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key using the supplied args, as defined inMessageFormat, or the provided key if no message is found.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- key- the resource bundle key that is to be searched for
- args- an array args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or the provided key if none is found.
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- aTextName- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- a list args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key using the supplied args, as defined inMessageFormat, or, if the message is not found, a supplied default value is returned.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- an array args to be used in a- MessageFormatmessage
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key using the supplied args, as defined inMessageFormat, 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.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- a list args to be used in a- MessageFormatmessage
- stack- the value stack to use for finding the text
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getTextDescription copied from interface:TextProviderGets a message based on a key using the supplied args, as defined inMessageFormat, 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.- Specified by:
- getTextin interface- TextProvider
- Parameters:
- key- the resource bundle key that is to be searched for
- defaultValue- the default value which will be returned if no message is found
- args- an array args to be used in a- MessageFormatmessage
- stack- the value stack to use for finding the text
- Returns:
- the message as found in the resource bundle, or defaultValue if none is found
 
- 
getFormattedDedicated method to support I10N and conversion errors- Parameters:
- key- message which contains formatting string
- expr- that should be formatted
- Returns:
- formatted expr with format specified by key
 
- 
getTextsDescription copied from interface:TextProviderGet the resource bundle associated with the implementing class (usually an action).- Specified by:
- getTextsin interface- TextProvider
- Returns:
- the bundle
 
- 
getTextsDescription copied from interface:TextProviderGet the named bundle, such as "com/acme/Foo".- Specified by:
- getTextsin interface- TextProvider
- Parameters:
- aBundleName- the name of the resource bundle, such as- "com/acme/Foo".
- Returns:
- the bundle
 
- 
addActionErrorDescription copied from interface:ValidationAwareAdd an Action-level error message to this Action.- Specified by:
- addActionErrorin interface- ValidationAware
- Parameters:
- anErrorMessage- the error message
 
- 
addActionMessageDescription copied from interface:ValidationAwareAdd an Action-level message to this Action.- Specified by:
- addActionMessagein interface- ValidationAware
- Parameters:
- aMessage- the message
 
- 
addFieldErrorDescription copied from interface:ValidationAwareAdd an error message for a given field.- Specified by:
- addFieldErrorin interface- ValidationAware
- Parameters:
- fieldName- name of field
- errorMessage- the error message
 
- 
input- Throws:
- Exception
 
- 
executeA default implementation that does nothing an returns "success".Subclasses should override this method to provide their business logic. See also Action.execute().- Specified by:
- executein interface- Action
- Returns:
- returns Action.SUCCESS
- Throws:
- Exception- can be thrown by subclasses.
 
- 
hasActionErrorspublic boolean hasActionErrors()Description copied from interface:ValidationAwareCheck whether there are any Action-level error messages.- Specified by:
- hasActionErrorsin interface- ValidationAware
- Returns:
- true if any Action-level error messages have been registered
 
- 
hasActionMessagespublic boolean hasActionMessages()Description copied from interface:ValidationAwareChecks whether there are any Action-level messages.- Specified by:
- hasActionMessagesin interface- ValidationAware
- Returns:
- true if any Action-level messages have been registered
 
- 
hasErrorspublic boolean hasErrors()Description copied from interface:ValidationAwareChecks whether there are any action errors or field errors.- Specified by:
- hasErrorsin interface- ValidationAware
- Returns:
- (hasActionErrors() || hasFieldErrors())
 
- 
hasFieldErrorspublic boolean hasFieldErrors()Description copied from interface:ValidationAwareCheck whether there are any field errors associated with this action.- Specified by:
- hasFieldErrorsin interface- ValidationAware
- Returns:
- whether there are any field errors
 
- 
clearFieldErrorspublic void clearFieldErrors()Clears field errors. Useful for Continuations and other situations where you might want to clear parts of the state on the same action.
- 
clearActionErrorspublic void clearActionErrors()Clears action errors. Useful for Continuations and other situations where you might want to clear parts of the state on the same action.
- 
clearMessagespublic void clearMessages()Clears messages. Useful for Continuations and other situations where you might want to clear parts of the state on the same action.
- 
clearErrorspublic void clearErrors()Clears all errors. Useful for Continuations and other situations where you might want to clear parts of the state on the same action.
- 
clearErrorsAndMessagespublic void clearErrorsAndMessages()Clears all errors and messages. Useful for Continuations and other situations where you might want to clear parts of the state on the same action.
- 
validatepublic void validate()A default implementation that validates nothing. Subclasses should override this method to provide validations.- Specified by:
- validatein interface- Validateable
 
- 
clone- Overrides:
- clonein class- Object
- Throws:
- CloneNotSupportedException
 
- 
pauseStops the action invocation immediately (by throwing a PauseException) and causes the action invocation to return the specified result, such asAction.SUCCESS,Action.INPUT, etc.The next time this action is invoked (and using the same continuation ID), the method will resume immediately after where this method was called, with the entire call stack in the execute method restored. Note: this method can only be called within the execute()method.- Parameters:
- result- the result to return - the same type of return value in the- execute()method.
 
- 
getTextProviderIf called first time it will createTextProviderFactory, inject dependency (ifContaineris accesible) into in, then will create newTextProviderand store it in a field for future references and at the returns reference to that field- Returns:
- reference to field with TextProvider
 
- 
getLocaleProvider
- 
getContainerTODO: This a temporary solution, maybe we should consider stop injecting container into beans
- 
setContainer
 
-