Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.struts.actions
Class DispatchAction

    java.lang.Object
      |
      +--org.apache.struts.action.Action
            |
            +--org.apache.struts.actions.DispatchAction

Direct Known Subclasses:
  LookupDispatchAction

public abstract class DispatchAction
extends Action

An abstract Action that dispatches to a public method that is named by the request parameter whose name is specified by the `parameter` property of the corresponding ActionMapping. This Action is useful for developers who prefer to combine many similar actions into a single Action class, in order to simplify their application design.

To configure the use of this action in your `struts-config.xml` file, create an entry like this:

`<action path="/saveSubscription" type="org.apache.struts.actions.DispatchAction" name="subscriptionForm" scope="request" input="/subscription.jsp" parameter="method"/>`

which will use the value of the request parameter named "method" to pick the appropriate "execute" method, which must have the same signature (other than method name) of the standard Action.execute method. For example, you might have the following three methods in the same action:

- public ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
- public ActionForward insert(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
- public ActionForward update(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception

and call one of the methods with a URL like this:

`http://localhost:8080/myapp/saveSubscription.do?method=update`

NOTE - All of the other mapping characteristics of this action must be shared by the various handlers. This places some constraints over what types of handlers may reasonably be packaged into the same `DispatchAction` subclass.

Version:
  $Revision: 1.1 $ $Date: 2003-08-22 09:14:33 +0100 (Fri, 22 Aug 2003) $
Author:
  Niall Pemberton , Craig R. McClanahan, Ted Husted

Field Summary
`protected java.lang.Class` | `clazz` The Class instance of this `DispatchAction` class.
`protected static org.apache.commons.logging.Log` | `log` Commons Logging instance.
`protected static MessageResources` | `messages` The message resources for this package.
`protected java.util.HashMap` | `methods` The set of Method objects we have introspected for this class, keyed by method name.
`protected java.lang.Class[]` | `types` The set of argument type classes for the reflected method call.

Fields inherited from class org.apache.struts.action.Action
`ACTION_SERVLET_KEY, APPLICATION_KEY, DATA_SOURCE_KEY, defaultLocale, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPING_KEY, MAPPINGS_KEY, MESSAGE_KEY, MESSAGES_KEY, MULTIPART_KEY, PLUG_INS_KEY, REQUEST_PROCESSOR_KEY, servlet, SERVLET_KEY, TRANSACTION_TOKEN_KEY`

Constructor Summary
`DispatchAction()`

Method Summary
`protected ActionForward` | `dispatchMethod(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String name)` Dispatch to the specified method.
`ActionForward` | `execute(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it).
`protected java.lang.reflect.Method` | `getMethod(java.lang.String name)` Introspect the current class to identify a method of the specified name that accepts the same parameter types as the `execute` method does.
`protected ActionForward` | `unspecified(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)` Method which is dispatched to when there is no value for specified request parameter included in the request.

Methods inherited from class org.apache.struts.action.Action
`execute, generateToken, getDataSource, getDataSource, getLocale, getResources, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, perform, perform, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet, toHex`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### clazz

    protected java.lang.Class clazz

  The Class instance of this `DispatchAction` class.

### log

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

  Commons Logging instance.

### messages

    protected static MessageResources messages

  The message resources for this package.

### methods

    protected java.util.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.

### types

    protected java.lang.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 Detail

### DispatchAction

    public DispatchAction()

Method Detail

### execute

    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 javax.servlet.http.HttpServletRequest request,
                                 javax.servlet.http.HttpServletResponse response)
                          throws java.lang.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.

  Overrides:
    `execute` in class `Action`
  Parameters:
    `mapping` - The ActionMapping used to select this instance
    `form` - The optional ActionForm bean for this request (if any)
    `request` - The HTTP request we are processing
    `response` - The HTTP response we are creating
  Throws:
    `java.lang.Exception` - if an exception occurs

### unspecified

    protected ActionForward unspecified(ActionMapping mapping,
                                        ActionForm form,
                                        javax.servlet.http.HttpServletRequest request,
                                        javax.servlet.http.HttpServletResponse response)
                                 throws java.lang.Exception

  Method which is dispatched to when there is no value for specified request parameter included in the request. Subclasses of `DispatchAction` should override this method if they wish to provide default behavior different than producing an HTTP "Bad Request" error.

    `java.lang.Exception`

### dispatchMethod

    protected ActionForward dispatchMethod(ActionMapping mapping,
                                           ActionForm form,
                                           javax.servlet.http.HttpServletRequest request,
                                           javax.servlet.http.HttpServletResponse response,
                                           java.lang.String name)
                                    throws java.lang.Exception

  Dispatch to the specified method.

    `java.lang.Exception`
  Since:
    Struts 1.1

### getMethod

    protected java.lang.reflect.Method getMethod(java.lang.String name)
                                          throws java.lang.NoSuchMethodException

  Introspect the current class to identify a method of the specified name that accepts the same parameter types as the `execute` method does.

  Parameters:
    `name` - Name of the method to be introspected
  Throws:
    `java.lang.NoSuchMethodException` - if no such method can be found

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2000-2003 - Apache Software Foundation