Home » Struts-1.3.10 » org.apache.struts » actions » [javadoc | source]
org.apache.struts.actions
public class: ActionDispatcher [javadoc | source]
java.lang.Object
   org.apache.struts.actions.ActionDispatcher

Direct Known Subclasses:
    EventActionDispatcher

Action helper class that dispatches to a public method in an Action.

This class is provided as an alternative mechanism to using DispatchAction and its various flavours and means Dispatch behaviour can be easily implemented into any Action without having to inherit from a particular super Action.

To implement dispatch behaviour in an Action class, create your custom Action as follows, along with the methods you require (and optionally "cancelled" and "unspecified" methods):

  public class MyCustomAction extends Action {

      protected ActionDispatcher dispatcher
               = new ActionDispatcher(this, ActionDispatcher.MAPPING_FLAVOR);

      public ActionForward execute(ActionMapping mapping,
                                   ActionForm form,
                                   HttpServletRequest request,
                                   HttpServletResponse response)
                          throws Exception {
          return dispatcher.execute(mapping, form, request, response);
      }
  }

It provides three flavours of determing the name of the method:

Field Summary
public static final  int DEFAULT_FLAVOR    Indicates "default" dispatch flavor 
public static final  int MAPPING_FLAVOR    Indicates "mapping" dispatch flavor 
public static final  int DISPATCH_FLAVOR    Indicates flavor compatible with DispatchAction 
protected  Action actionInstance    The associated Action to dispatch to. 
protected  int flavor    Indicates dispatch flavor 
protected  Class clazz    The Class instance of this DispatchAction class. 
protected static  Log log    Commons Logging instance. 
protected static  MessageResources messages    The message resources for this package. 
protected  HashMap methods    The set of Method objects we have introspected for this class, keyed by method name. This collection is populated as different methods are called, so that introspection needs to occur only once per method name. 
protected  Class[] types    The set of argument type classes for the reflected method call. These are the same for all calls, so calculate them only once. 
Constructor:
 public ActionDispatcher(Action actionInstance) 
 public ActionDispatcher(Action actionInstance,
    int flavor) 
Method from org.apache.struts.actions.ActionDispatcher Summary:
cancelled,   dispatchMethod,   dispatchMethod,   execute,   getMethod,   getMethodName,   getParameter,   isCancelled,   unspecified
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.struts.actions.ActionDispatcher Detail:
 protected ActionForward cancelled(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception 

    Dispatches to the target class' cancelled method, if present, otherwise returns null. Classes utilizing ActionDispatcher should provide a cancelled method if they wish to provide behavior different than returning null.

 protected ActionForward dispatchMethod(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response,
    String name) throws Exception 
    Dispatch to the specified method.
 protected ActionForward dispatchMethod(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response,
    String name,
    Method method) throws Exception 
    Dispatch to the specified method.
 public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception 
    Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it). Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed.
 protected Method getMethod(String name) throws NoSuchMethodException 
    Introspect the current class to identify a method of the specified name that accepts the same parameter types as the execute method does.
 protected String getMethodName(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response,
    String parameter) throws Exception 
    Returns the method name, given a parameter's value.
 protected String getParameter(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception 

    Returns the parameter value as influenced by the selected #flavor specified for this ActionDispatcher.

 protected boolean isCancelled(HttpServletRequest request) 

    Returns true if the current form's cancel button was pressed. This method will check if the Globals.CANCEL_KEY request attribute has been set, which normally occurs if the cancel button generated by CancelTag was pressed by the user in the current request. If true, validation performed by an ActionForm's validate() method will have been skipped by the controller servlet.

 protected ActionForward unspecified(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception 

    Dispatches to the target class' unspecified method, if present, otherwise throws a ServletException. Classes utilizing ActionDispatcher should provide an unspecified method if they wish to provide behavior different than throwing a ServletException..