webwork.action
Class ActionSupport

java.lang.Object
  extended bywebwork.action.ActionSupport
All Implemented Interfaces:
Action, IllegalArgumentAware, java.io.Serializable
Direct Known Subclasses:
ActionListing, AgeList, Bar, BeanUtilTest, BookList, CardPane, CascadingSelectTest, ClientInfo, CountryMap, ExprFormTest, FileUploadTest, Foo, FormTest, GenderMap, HelloAction, HelloWorld, HitUrl, JDOMTest, JDOMUrl, JSP, LanguageList, LoanCalc, Login, Login, LoginCounter, LoginStatus, Logout, MonthSelector, MultiForm, NumberGuess, OrderList, Primes, Redirect, Script, ServletTest, Shop, SystemInfo, TabbedPaneTest, TableAction, Test, Transfer, VXMLTest, XML, XSLTTest

public class ActionSupport
extends java.lang.Object
implements Action, java.io.Serializable, IllegalArgumentAware

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.50 $
Author:
Rickard Oberg (rickard@middleware-company.com), Victor Salaman (salaman@qoretech.com)
See Also:
Action, Serialized Form

Field Summary
protected  java.lang.String command
           
protected  java.util.Map errorMap
           
protected  java.util.Collection errorMessages
           
protected  org.apache.commons.logging.Log log
           
 
Fields inherited from interface webwork.action.Action
ERROR, INPUT, LOGIN, NONE, SUCCESS
 
Constructor Summary
ActionSupport()
           
 
Method Summary
 void addError(java.lang.String fieldName, java.lang.String errorMessage)
          This method is used to attach an error message to a particular form field.
 void addErrorMessage(java.lang.String anErrorMessage)
          Add an error message to this action
 void addIllegalArgumentException(java.lang.String fieldName, java.lang.IllegalArgumentException e)
           
 java.lang.String doDefault()
          "default" command
protected  java.lang.String doExecute()
           
protected  void doValidation()
          Subclasses may override this method to provide validation of input data.
 java.lang.String execute()
          Execute will first check the request for a result exception.
protected  java.lang.String getActionName()
          This is used to get the current action's class name
 java.util.Collection getErrorMessages()
          Get the list of error messages for this action
 java.util.Map getErrors()
          Get the field specific errors associated with this action.
 boolean getHasErrorMessages()
          Check whether there are any error messages
 boolean getHasErrors()
          Check whether there are any errors associated with this action.
 java.util.Locale getLocale()
          Get the locale for this action.
protected  java.lang.String getPropertyEditorMessage(java.lang.String fieldName, PropertyEditorException pe)
          This method is called from addIllegalArgumentException and it should return an error message (that may be localized).
 java.lang.String getText(java.lang.String aTextName)
          Get a text from the resource bundles associated with this action.
 java.util.ResourceBundle getTexts()
          Get the resource bundle associated with this action.
 java.util.ResourceBundle getTexts(java.lang.String aBundleName)
          Get the named bundle.
 boolean invalidInput()
          Check whether there are any error messages.
protected  java.lang.String invokeCommand()
          Invokes an alternate execution path for the action.
 boolean isCommand(java.lang.String aName)
          Detect whether a particular command has been issued
 void setCommand(java.lang.String command)
          Support implementation of CommandDriven interface.
 void setErrorMessages(java.util.Collection errorMessages)
           
 void setErrors(java.util.Map errorMap)
           
protected  void validate()
          Do validation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected transient org.apache.commons.logging.Log log

errorMap

protected java.util.Map errorMap

errorMessages

protected java.util.Collection errorMessages

command

protected java.lang.String command
Constructor Detail

ActionSupport

public ActionSupport()
Method Detail

addIllegalArgumentException

public void addIllegalArgumentException(java.lang.String fieldName,
                                        java.lang.IllegalArgumentException e)
Specified by:
addIllegalArgumentException in interface IllegalArgumentAware

getPropertyEditorMessage

protected java.lang.String getPropertyEditorMessage(java.lang.String fieldName,
                                                    PropertyEditorException pe)
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

public void setCommand(java.lang.String command)
Support implementation of CommandDriven interface. Let your action subclasses implement CommandDriven if they support this notion.

See Also:
CommandDriven

isCommand

public boolean isCommand(java.lang.String aName)
Detect whether a particular command has been issued


execute

public java.lang.String execute()
                         throws java.lang.Exception
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().

Specified by:
execute in interface Action
Returns:
view
Throws:
java.lang.Exception - thrown if a system level exception occurs. Application level exceptions should be handled by returning an error value, such as Action.ERROR.

doDefault

public java.lang.String doDefault()
                           throws java.lang.Exception
"default" command

Throws:
java.lang.Exception

getErrorMessages

public java.util.Collection getErrorMessages()
Get the list of error messages for this action

Returns:
list of error messages

setErrorMessages

public void setErrorMessages(java.util.Collection errorMessages)

getHasErrorMessages

public boolean getHasErrorMessages()
Check whether there are any error messages

Returns:
true if any error messages have been registered

addErrorMessage

public void addErrorMessage(java.lang.String anErrorMessage)
Add an error message to this action

Parameters:
anErrorMessage -

addError

public void addError(java.lang.String fieldName,
                     java.lang.String errorMessage)
This method is used to attach an error message to a particular form field.

Parameters:
fieldName - name of field
errorMessage - the error message

getErrors

public java.util.Map getErrors()
Get the field specific errors associated with this action.

Returns:
map with errors

setErrors

public void setErrors(java.util.Map errorMap)

getHasErrors

public boolean getHasErrors()
Check whether there are any errors associated with this action.

Returns:
whether there are any errors

getLocale

public java.util.Locale 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

public java.util.ResourceBundle getTexts(java.lang.String aBundleName)
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

public java.util.ResourceBundle getTexts()
Get the resource bundle associated with this action. This will be based on the actual subclass that is used.

Returns:
resouce bundle

getText

public java.lang.String getText(java.lang.String aTextName)
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

protected java.lang.String doExecute()
                              throws java.lang.Exception
Throws:
java.lang.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

protected void validate()
                 throws ResultException
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

protected java.lang.String invokeCommand()
                                  throws java.lang.Exception
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:
java.lang.Exception

getActionName

protected java.lang.String getActionName()
This is used to get the current action's class name



Copyright © 2001-2003 WebWork All Rights Reserved.