|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.struts.actions.ActionDispatcher org.apache.struts.actions.EventActionDispatcher
public class EventActionDispatcher
An Action helper class that dispatches to to one of the public methods
that are named in the parameter
attribute of the corresponding
ActionMapping and matches a submission parameter. This is useful for
developers who prefer to use many submit buttons, images, or submit links
on a single form and whose related actions exist in a single Action class.
The method(s) in the associated Action
must have the same
signature (other than method name) of the standard Action.execute method.
To configure the use of this action in your
struts-config.xml
file, create an entry like this:
<action path="/saveSubscription"
type="org.example.SubscriptionAction"
name="subscriptionForm"
scope="request"
input="/subscription.jsp"
parameter="save,back,recalc=recalculate,default=save"/>
where parameter
contains three possible methods and one
default method if nothing matches (such as the user pressing the enter key).
For utility purposes, you can use the key=value
notation to
alias methods so that they are exposed as different form element names, in the
event of a naming conflict or otherwise. In this example, the recalc
button (via a request parameter) will invoke the recalculate
method. The security-minded person may find this feature valuable to
obfuscate and not expose the methods.
The default key is purely optional. If this is not specified
and no parameters match the list of method keys, null
is
returned which means the unspecified
method will be invoked.
The order of the parameters are guaranteed to be iterated in the order specified. If multiple buttons were accidently submitted, the first match in the list will be dispatched.
To implement this 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 EventActionDispatcher(this); public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return dispatcher.execute(mapping, form, request, response); } }
Field Summary |
---|
Fields inherited from class org.apache.struts.actions.ActionDispatcher |
---|
actionInstance, clazz, DEFAULT_FLAVOR, DISPATCH_FLAVOR, flavor, log, MAPPING_FLAVOR, messages, methods, types |
Constructor Summary | |
---|---|
EventActionDispatcher(Action action)
Constructs a new object for the specified action. |
Method Summary | |
---|---|
protected java.lang.String |
getMethodName(ActionMapping mapping,
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 ActionForward |
unspecified(ActionMapping mapping,
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 org.apache.struts.actions.ActionDispatcher |
---|
cancelled, dispatchMethod, dispatchMethod, execute, getMethod, getParameter, isCancelled |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public EventActionDispatcher(Action action)
action
- the actionMethod Detail |
---|
protected ActionForward unspecified(ActionMapping mapping, 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
EventActionDispatcher
should provide an unspecified
method if they wish to provide behavior different than throwing a
ServletException.
unspecified
in class ActionDispatcher
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 java.lang.String getMethodName(ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String parameter) throws java.lang.Exception
getMethodName
in class 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 creatingparameter
- The ActionMapping
parameter's name
java.lang.Exception
- if an error occurs.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |