|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.struts.actions.ActionDispatcher
public class ActionDispatcher
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:
DEFAULT_FLAVOR
- uses the parameter
specified in the struts-config.xml to get the method name from the Request
(equivalent to DispatchAction
except uses "method" as a
default if the parameter
is not specified in the
struts-config.xml).DISPATCH_FLAVOR
- uses the parameter specified in the struts-config.xml to get the method
name from the Request (equivalent to DispatchAction
).MAPPING_FLAVOR
- uses the parameter
specified in the struts-config.xml as the method name (equivalent to
MappingDispatchAction
).
Field Summary | |
---|---|
protected org.apache.struts.action.Action |
actionInstance
The associated Action to dispatch to. |
protected java.lang.Class |
clazz
The Class instance of this DispatchAction class. |
static int |
DEFAULT_FLAVOR
Indicates "default" dispatch flavor. |
static int |
DISPATCH_FLAVOR
Indicates flavor compatible with DispatchAction. |
protected int |
flavor
Indicates dispatch flavor. |
protected static org.apache.commons.logging.Log |
log
Commons Logging instance. |
static int |
MAPPING_FLAVOR
Indicates "mapping" dispatch flavor. |
protected static org.apache.struts.util.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. |
Constructor Summary | |
---|---|
ActionDispatcher(org.apache.struts.action.Action actionInstance)
Construct an instance of this class from the supplied parameters. |
|
ActionDispatcher(org.apache.struts.action.Action actionInstance,
int flavor)
Construct an instance of this class from the supplied parameters. |
Method Summary | |
---|---|
protected org.apache.struts.action.ActionForward |
cancelled(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Dispatches to the target class' cancelled method, if present, otherwise returns null. |
protected org.apache.struts.action.ActionForward |
dispatchMethod(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String name)
Dispatch to the specified method. |
protected org.apache.struts.action.ActionForward |
dispatchMethod(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String name,
java.lang.reflect.Method method)
Dispatch to the specified method. |
org.apache.struts.action.ActionForward |
execute(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.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 java.lang.String |
getMethodName(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String parameter)
Returns the method name, given a parameter's value. |
protected java.lang.String |
getParameter(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Returns the parameter value as influenced by the selected flavor specified for this ActionDispatcher . |
protected boolean |
isCancelled(javax.servlet.http.HttpServletRequest request)
Returns true if the current form's cancel button was
pressed. |
protected org.apache.struts.action.ActionForward |
unspecified(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Dispatches to the target class' unspecified method, if
present, otherwise throws a ServletException. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_FLAVOR
public static final int MAPPING_FLAVOR
public static final int DISPATCH_FLAVOR
protected static org.apache.commons.logging.Log log
protected static org.apache.struts.util.MessageResources messages
protected org.apache.struts.action.Action actionInstance
protected int flavor
protected java.lang.Class clazz
DispatchAction
class.
protected java.util.HashMap methods
protected java.lang.Class[] types
Constructor Detail |
---|
public ActionDispatcher(org.apache.struts.action.Action actionInstance)
actionInstance
- The action instance to be invoked.public ActionDispatcher(org.apache.struts.action.Action actionInstance, int flavor)
actionInstance
- The action instance to be invoked.flavor
- The flavor of dispatch to use.Method Detail |
---|
public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
ActionForward
instance describing where and how
control should be forwarded, or null
if the response has
already been completed.
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The HTTP request we are processingresponse
- The HTTP response we are creating
null
if the response has been completed.
java.lang.Exception
- if an exception occursprotected org.apache.struts.action.ActionForward unspecified(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.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.
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The non-HTTP request we are processingresponse
- The non-HTTP response we are creating
null
if the response has been completed.
java.lang.Exception
- if the application business logic throws an
exception.protected org.apache.struts.action.ActionForward cancelled(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.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.
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The non-HTTP request we are processingresponse
- The non-HTTP response we are creating
null
if the response has been completed.
java.lang.Exception
- if the application business logic throws an
exception.protected org.apache.struts.action.ActionForward dispatchMethod(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String name) throws java.lang.Exception
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The non-HTTP request we are processingresponse
- The non-HTTP response we are creatingname
- The name of the method to invoke
null
if the response has been completed.
java.lang.Exception
- if the application business logic throws an
exception.protected org.apache.struts.action.ActionForward dispatchMethod(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String name, java.lang.reflect.Method method) throws java.lang.Exception
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The non-HTTP request we are processingresponse
- The non-HTTP response we are creatingname
- The name of the method to invokemethod
- The method to invoke
null
if the response has been completed.
java.lang.Exception
- if the application business logic throws an
exception.protected java.lang.reflect.Method getMethod(java.lang.String name) throws java.lang.NoSuchMethodException
execute
method does.
name
- Name of the method to be introspected
java.lang.NoSuchMethodException
- if no such method can be foundprotected java.lang.String getParameter(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
Returns the parameter value as influenced by the selected flavor
specified for this ActionDispatcher
.
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The HTTP request we are processingresponse
- The HTTP response we are creating
ActionMapping
parameter's value
java.lang.Exception
- if an error occurs.protected java.lang.String getMethodName(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String parameter) throws java.lang.Exception
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if
any)request
- The HTTP request we are processingresponse
- The HTTP response we are creatingparameter
- The ActionMapping
parameter's name
java.lang.Exception
- if an error occurs.protected boolean isCancelled(javax.servlet.http.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.
request
- The servlet request we are processing
true
if the current form's cancel button was
pressed; false
otherwise.org.apache.struts.taglib.html.CancelTag
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |