org.appfuse.webapp.action
Class BaseAction

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by org.apache.struts.actions.DispatchAction
          extended by org.appfuse.webapp.action.BaseAction
Direct Known Subclasses:
PasswordHintAction, ReloadAction, SignupAction, UserAction

public class BaseAction
extends DispatchAction

Implementation of Action that contains base methods for Actions as well as determines with methods to call in subclasses. This class uses the name of the button to determine which method to execute on the Action.

For example look at the following two buttons:

    <html:submit property="method.findName">
       <bean:message key="email.find"/>
    </html:submit>

    <html:submit property="method.findEmail">
       <bean:message key="email.find"/>
    </html:submit>
   

The name of the button is set with the property parameter, i.e., the name of the first button is method.findName. The name of the second button is method.findEmail.

As per HTML/HTTP, whatever submit button that is pushed causes only that submit button's name to be sent as a request parameter to the action.

This action looks for the name by removing the prepender string "method.". The remaining part of the string is the name of the method to execute, e.g., pushing the first button will execute the findName method and the second button will execute the findEmail method.

This class extends DispatchAction and allows methods to be sent as regular GETs as well, i.e., <a href="emailAction.do?method=findEmail"/> would cause the findEmail method to be executed just as it would in a DispatchAction. Thus, you configure a ButtonNameDispatchAction exactly the way you configure a DispatchAction, i.e., set the mapping parameter to the name of the request parameter that holds the mehtod name.

View Source

Author:
Matt Raible, Rick Hightower (based on his ButtonNameDispatchAction)

Field Summary
protected  org.apache.commons.logging.Log log
           
 
Fields inherited from class org.apache.struts.actions.DispatchAction
clazz, messages, methods, types
 
Fields inherited from class org.apache.struts.action.Action
defaultLocale, servlet
 
Constructor Summary
BaseAction()
           
 
Method Summary
protected  Object convert(Object o)
           
protected  Object convertLists(Object o)
           
 ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
          Override the execute method in DispatchAction to parse URLs and forward to methods without parameters.
protected  ActionForm getActionForm(ActionMapping mapping, HttpServletRequest request)
          Convenience method for getting an action form base on it's mapped scope.
protected  String getActionMethod(HttpServletRequest request, String prepend)
          Gets the method name based on the prepender passed to it.
 Object getBean(String name)
          Convenience method to get Spring-initialized beans
 Map getConfiguration()
          Convenience method to get the Configuration HashMap from the servlet context.
 ActionMessages getMessages(HttpServletRequest request)
          Convenience method to initialize messages in a subclass.
protected  void removeFormBean(ActionMapping mapping, HttpServletRequest request)
          Convenience method for removing the obsolete form bean.
protected  void updateFormBean(ActionMapping mapping, HttpServletRequest request, ActionForm form)
          Convenience method to update a formBean in it's scope
 
Methods inherited from class org.apache.struts.actions.DispatchAction
cancelled, dispatchMethod, getMethod, getMethodName, getParameter, unspecified
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final org.apache.commons.logging.Log log
Constructor Detail

BaseAction

public BaseAction()
Method Detail

getBean

public Object getBean(String name)
Convenience method to get Spring-initialized beans

Parameters:
name -
Returns:
Object bean from ApplicationContext

convert

protected Object convert(Object o)
                  throws Exception
Throws:
Exception
See Also:
ConvertUtil.convert(java.lang.Object)

convertLists

protected Object convertLists(Object o)
                       throws Exception
Throws:
Exception
See Also:
ConvertUtil.convertLists(java.lang.Object)

getMessages

public ActionMessages getMessages(HttpServletRequest request)
Convenience method to initialize messages in a subclass.

Overrides:
getMessages in class Action
Parameters:
request - the current request
Returns:
the populated (or empty) messages

getActionMethod

protected String getActionMethod(HttpServletRequest request,
                                 String prepend)
Gets the method name based on the prepender passed to it.


execute

public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response)
                      throws Exception
Override the execute method in DispatchAction to parse URLs and forward to methods without parameters.

This is based on the following system:

Overrides:
execute in class DispatchAction
Throws:
Exception

getActionForm

protected ActionForm getActionForm(ActionMapping mapping,
                                   HttpServletRequest request)
Convenience method for getting an action form base on it's mapped scope.

Parameters:
mapping - The ActionMapping used to select this instance
request - The HTTP request we are processing
Returns:
ActionForm the form from the specifies scope, or null if nothing found

getConfiguration

public Map getConfiguration()
Convenience method to get the Configuration HashMap from the servlet context.

Returns:
the user's populated form from the session

removeFormBean

protected void removeFormBean(ActionMapping mapping,
                              HttpServletRequest request)
Convenience method for removing the obsolete form bean.

Parameters:
mapping - The ActionMapping used to select this instance
request - The HTTP request we are processing

updateFormBean

protected void updateFormBean(ActionMapping mapping,
                              HttpServletRequest request,
                              ActionForm form)
Convenience method to update a formBean in it's scope

Parameters:
mapping - The ActionMapping used to select this instance
request - The HTTP request we are processing
form - The ActionForm


Copyright � 2002-2006