Package webwork.action
Class ActionSupport
java.lang.Object
webwork.action.ActionSupport
- All Implemented Interfaces:
Serializable,Action,IllegalArgumentAware
- Direct Known Subclasses:
CardPane,ExternalImport,JiraWebActionSupport,JSP,MockAction,Redirect,XML
This is a useful base class for WebWork Action implementations. It gives you access to a set of useful functionality,
including result view mapping, error handling, and i18n.
It is also possible to use this class by way of delegation instead of subclassing. This is useful in the case that
your action cannot use subclassing to add functionality
- Version:
- $Revision: 1.54 $
- Author:
- Rickard Öberg (rickard@middleware-company.com), Victor Salaman (salaman@qoretech.com)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected Mapprotected Collectionprotected org.apache.commons.logging.Log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis method is used to attach an error message to a particular form field.voidaddErrorMessage(String anErrorMessage) Add an error message to this actionvoidaddIllegalArgumentException(String fieldName, IllegalArgumentException e) "default" commandprotected Stringprotected voidSubclasses may override this method to provide validation of input data.execute()Execute will first check the request for a result exception.protected StringThis is used to get the current action's class nameGet the list of error messages for this actionGet the field specific errors associated with this action.booleanCheck whether there are any error messagesbooleanCheck whether there are any errors associated with this action.Get the locale for this action.protected StringgetPropertyEditorMessage(String fieldName, PropertyEditorException pe) This method is called from addIllegalArgumentException and it should return an error message (that may be localized).Get a text from the resource bundles associated with this action.getTexts()Get the resource bundle associated with this action.Get the named bundle.Get the user's timezone for date/time formatting in text tag.booleanCheck whether there are any error messages.protected StringInvokes an alternate execution path for the action.booleanDetect whether a particular command has been issuedvoidsetCommand(String command) Support implementation of CommandDriven interface.voidsetErrorMessages(Collection errorMessages) voidprotected voidvalidate()Do validation.
-
Field Details
-
log
protected transient org.apache.commons.logging.Log log -
errorMap
-
errorMessages
-
command
-
-
Constructor Details
-
ActionSupport
public ActionSupport()
-
-
Method Details
-
addIllegalArgumentException
- Specified by:
addIllegalArgumentExceptionin interfaceIllegalArgumentAware
-
getPropertyEditorMessage
This method is called from addIllegalArgumentException and it should return an error message (that may be localized). The implementation here does this by calling the getText method but you may override it with your own implementation. The default messages are stored in the ActionSupport.properties file -
setCommand
Support implementation of CommandDriven interface. Let your action subclasses implement CommandDriven if they support this notion.- See Also:
-
isCommand
Detect whether a particular command has been issued -
getCommandName
-
execute
Execute will first check the request for a result exception. If one is found, then it will add its message as an error message and throw the ResultException. If there no exception is found, then it will invoke the "command" - invokeCommand(). If we are not invoking a command, it will call validate() and then doExecute(). -
doDefault
"default" command- Throws:
Exception
-
getErrorMessages
Get the list of error messages for this action- Returns:
- list of error messages
-
setErrorMessages
-
getHasErrorMessages
public boolean getHasErrorMessages()Check whether there are any error messages- Returns:
- true if any error messages have been registered
-
addErrorMessage
Add an error message to this action- Parameters:
anErrorMessage-
-
addError
This method is used to attach an error message to a particular form field.- Parameters:
fieldName- name of fielderrorMessage- the error message
-
getErrors
Get the field specific errors associated with this action.- Returns:
- map with errors
-
setErrors
-
getHasErrors
public boolean getHasErrors()Check whether there are any errors associated with this action.- Returns:
- whether there are any errors
-
getLocale
Get the locale for this action. Applications may customize how locale is chosen by subclassing ActionSupport and override this method.- Returns:
- the locale to use
-
getTexts
Get the named bundle. You can override the getLocale() method to change the behaviour of how to choose locale for the bundles that are returned. Typically you would use the LocaleAware interface to get the users configured locale, or use your own method to allow the user to select the locale and store it in the session (by using the SessionAware interface).- Parameters:
aBundleName- bundle name- Returns:
- a resource bundle
-
getTexts
Get the resource bundle associated with this action. This will be based on the actual subclass that is used.- Returns:
- resouce bundle
-
getText
Get a text from the resource bundles associated with this action. The resource bundles are searched, starting with the one associated with this particular action, and testing all its superclasses' bundles. It will stop once a bundle is found that contains the given text. This gives a cascading style that allow global texts to be defined for an application base class.- Parameters:
aTextName- name of text to be found- Returns:
- value of named text
-
doExecute
- Throws:
Exception
-
doValidation
protected void doValidation()Subclasses may override this method to provide validation of input data. The execute() method should call validate() in the beginning of its code (which will delegate to this method), so as to check input data before doing the actual processing. If any application errors arise these should be registered by calling addErrorMessage or addError . If the validation is dependent on whether a command has been issued, and what that command is, then the isCommand() method should be used. -
validate
Do validation. This method is called implicitly before executing doExecute(), but must be called explicitly from within command implementation methods. The actual validation should be done by overriding the doValidation() method. If any errors have been registered by doValidation() this method will throw ResultException() which should simply be passed through.- Throws:
ResultException
-
invalidInput
public boolean invalidInput()Check whether there are any error messages. Just a nicer way of doing "getHasErrorMessages() || getHasErrors()".- Returns:
- true if any error messages have been registered
-
invokeCommand
Invokes an alternate execution path for the action. The name of the action is derived by prepending a "do" and capitalizing the first letter of the action.- Throws:
Exception
-
getActionName
This is used to get the current action's class name -
getTimezone
Get the user's timezone for date/time formatting in text tag.- Returns:
- null if the default timezone should be used
-