com.opensymphony.xwork
Class ActionSupport

java.lang.Object
  extended bycom.opensymphony.xwork.ActionSupport
All Implemented Interfaces:
Action, LocaleProvider, Serializable, TextProvider, Validateable, ValidationAware

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:
Serialized Form

Field Summary
protected static org.apache.commons.logging.Log LOG
           
 
Fields inherited from interface com.opensymphony.xwork.Action
ERROR, INPUT, LOGIN, NONE, SUCCESS
 
Constructor Summary
ActionSupport()
           
 
Method Summary
 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.
 String doDefault()
           
 String execute()
          A default implementation that does nothing an returns "success".
 Collection getActionErrors()
          Get the Collection of Action-level error messages for this action.
 Collection getActionMessages()
          Get the Collection of Action-level messages for this action.
 Collection getErrorMessages()
          Deprecated. Use getActionErrors().
 Map getErrors()
          Deprecated. Use getFieldErrors().
 Map getFieldErrors()
          Get the field specific errors associated with this action.
 Locale getLocale()
           
 String getText(String aTextName)
          Gets a message based on a message key, or null if no message is found.
 String getText(String aTextName, List args)
          Gets a message based on a key using the supplied args, as defined in MessageFormat, or null 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 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, OgnlValueStack 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.
 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".
 boolean hasActionErrors()
          Check whether there are any Action-level error messages.
 boolean hasActionMessages()
          Checks whether there are any Action-level messages.
 boolean hasErrors()
          Note that this does not have the same meaning as in WW 1.x.
 boolean hasFieldErrors()
          Check whether there are any field errors associated with this action.
 void setActionErrors(Collection errorMessages)
          Set the Collection of Action-level String error messages.
 void setActionMessages(Collection messages)
          Set the Collection of Action-level String messages (not errors).
 void setFieldErrors(Map errorMap)
          Set the field error map of fieldname (String) to Collection of String error messages.
 void validate()
          A default implementation that validates nothing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static final transient org.apache.commons.logging.Log LOG
Constructor Detail

ActionSupport

public ActionSupport()
Method Detail

setActionErrors

public void setActionErrors(Collection errorMessages)
Description copied from interface: ValidationAware
Set the Collection of Action-level String error messages.

Specified by:
setActionErrors in interface ValidationAware
Parameters:
errorMessages -

getActionErrors

public Collection getActionErrors()
Description copied from interface: ValidationAware
Get 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:
getActionErrors in interface ValidationAware
Returns:
Collection of String error messages

setActionMessages

public void setActionMessages(Collection messages)
Description copied from interface: ValidationAware
Set the Collection of Action-level String messages (not errors).

Specified by:
setActionMessages in interface ValidationAware

getActionMessages

public Collection getActionMessages()
Description copied from interface: ValidationAware
Get 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:
getActionMessages in interface ValidationAware
Returns:
Collection of String messages

getErrorMessages

public Collection getErrorMessages()
Deprecated. Use getActionErrors().


getErrors

public Map getErrors()
Deprecated. Use getFieldErrors().


setFieldErrors

public void setFieldErrors(Map errorMap)
Description copied from interface: ValidationAware
Set the field error map of fieldname (String) to Collection of String error messages.

Specified by:
setFieldErrors in interface ValidationAware
Parameters:
errorMap -

getFieldErrors

public Map getFieldErrors()
Description copied from interface: ValidationAware
Get 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:
getFieldErrors in interface ValidationAware
Returns:
a Map of field names -> List of errors or null if no errors have been added

getLocale

public Locale getLocale()
Specified by:
getLocale in interface LocaleProvider

getText

public String getText(String aTextName)
Description copied from interface: TextProvider
Gets a message based on a message key, or null if no message is found.

Specified by:
getText in interface TextProvider
Parameters:
aTextName - the resource bundle key that is to be searched for
Returns:
the message as found in the resource bundle, or null if none is found.

getText

public String getText(String aTextName,
                      String defaultValue)
Description copied from interface: TextProvider
Gets a message based on a key, or, if the message is not found, a supplied default value is returned.

Specified by:
getText in 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

getText

public String getText(String aTextName,
                      List args)
Description copied from interface: TextProvider
Gets a message based on a key using the supplied args, as defined in MessageFormat, or null if no message is found.

Specified by:
getText in interface TextProvider
Parameters:
aTextName - the resource bundle key that is to be searched for
args - a list args to be used in a MessageFormat message
Returns:
the message as found in the resource bundle, or null if none is found.

getText

public String getText(String aTextName,
                      String defaultValue,
                      List args)
Description copied from interface: TextProvider
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.

Specified by:
getText in 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 MessageFormat message
Returns:
the message as found in the resource bundle, or defaultValue if none is found

getTexts

public ResourceBundle getTexts(String aBundleName)
Description copied from interface: TextProvider
Get the named bundle, such as "com/acme/Foo".

Specified by:
getTexts in interface TextProvider
Parameters:
aBundleName - the name of the resource bundle, such as "com/acme/Foo"

getText

public String getText(String key,
                      String defaultValue,
                      List args,
                      OgnlValueStack stack)
Description copied from interface: TextProvider
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. Instead of using the value stack in the ActionContext this version of the getText() method uses the provided value stack.

Specified by:
getText in 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 MessageFormat message
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

getTexts

public ResourceBundle getTexts()
Description copied from interface: TextProvider
Get the resource bundle associated with the implementing class (usually an action).

Specified by:
getTexts in interface TextProvider

addActionError

public void addActionError(String anErrorMessage)
Description copied from interface: ValidationAware
Add an Action-level error message to this Action.

Specified by:
addActionError in interface ValidationAware
Parameters:
anErrorMessage -

addActionMessage

public void addActionMessage(String aMessage)
Description copied from interface: ValidationAware
Add an Action-level message to this Action.

Specified by:
addActionMessage in interface ValidationAware

addFieldError

public void addFieldError(String fieldName,
                          String errorMessage)
Description copied from interface: ValidationAware
Add an error message for a given field.

Specified by:
addFieldError in interface ValidationAware
Parameters:
fieldName - name of field
errorMessage - the error message

doDefault

public String doDefault()
                 throws Exception
Throws:
Exception

execute

public String execute()
               throws Exception
A default implementation that does nothing an returns "success".

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

hasActionErrors

public boolean hasActionErrors()
Description copied from interface: ValidationAware
Check whether there are any Action-level error messages.

Specified by:
hasActionErrors in interface ValidationAware
Returns:
true if any Action-level error messages have been registered

hasActionMessages

public boolean hasActionMessages()
Checks whether there are any Action-level messages.

Specified by:
hasActionMessages in interface ValidationAware
Returns:
true if any Action-level messages have been registered

hasErrors

public boolean hasErrors()
Description copied from interface: ValidationAware
Note that this does not have the same meaning as in WW 1.x.

Specified by:
hasErrors in interface ValidationAware
Returns:
(hasActionErrors() || hasFieldErrors())

hasFieldErrors

public boolean hasFieldErrors()
Description copied from interface: ValidationAware
Check whether there are any field errors associated with this action.

Specified by:
hasFieldErrors in interface ValidationAware
Returns:
whether there are any field errors

validate

public void validate()
A default implementation that validates nothing. Subclasses should override this method to provide validations.

Specified by:
validate in interface Validateable

XWork Project Page