| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectorg.apache.struts.action.Actionorg.apache.struts.actions.DispatchActionorg.apache.struts.actions.LookupDispatchActionpublic abstract class LookupDispatchActionextends DispatchActionexecute method. This is useful in
cases where an HTML form has multiple submit buttons with the same name. The
button name is specified by the parameter property of the
corresponding ActionMapping. To configure the use of this action in your
struts-config.xml file, create an entry like this:
<action path="/test"
type="org.example.MyAction"
name="MyForm"
scope="request"
input="/test.jsp"
parameter="action"/>
which will use the value of the request parameter named "action" to locate
the corresponding key in ApplicationResources. For example, you might have
the following ApplicationResources.properties:
button.add=Add Record
button.delete=Delete Record
And your JSP would have the following format for submit buttons:
<html:form action="/test">
<html:submit property="action">
<bean:message key="button.add"/>
</html:submit>
<html:submit property="action">
<bean:message key="button.delete"/>
</html:submit>
</html:form>
Your subclass must implement both getKeyMethodMap and the
methods defined in the map. An example of such implementations are:
protected Map getKeyMethodMap() {
Map map = new HashMap();
map.put("button.add", "add");
map.put("button.delete", "delete");
return map;
}
public ActionForward add(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do add
return mapping.findForward("success");
}
public ActionForward delete(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
// do delete
return mapping.findForward("success");
}
Notes - If duplicate values exist for the keys returned by
getKeys, only the first one found will be returned. If no corresponding key
is found then an exception will be thrown.
Field Summary | |
protected Map |
|
protected Map |
|
Fields inherited from class org.apache.struts.actions.DispatchAction | |
clazz, log, messages, methods, types | |
Fields inherited from class org.apache.struts.action.Action | |
ACTION_SERVLET_KEY, APPLICATION_KEY, DATA_SOURCE_KEY, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPINGS_KEY, MAPPING_KEY, MESSAGES_KEY, MESSAGE_KEY, MULTIPART_KEY, PLUG_INS_KEY, REQUEST_PROCESSOR_KEY, SERVLET_KEY, TRANSACTION_TOKEN_KEY, defaultLocale, servlet, token | |
Method Summary | |
ActionForward |
|
protected Map |
|
Methods inherited from class org.apache.struts.actions.DispatchAction | |
dispatchMethod, execute, getMethod, unspecified | |
Methods inherited from class org.apache.struts.action.Action | |
execute, execute, generateToken, getDataSource, getDataSource, getLocale, getResources, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, perform, perform, resetToken, saveErrors, saveMessages, saveToken, setLocale, setServlet, toHex | |
protected Map keyMethodMap
Resource key to method name lookup.
protected Map localeMap
Reverse lookup map from resource value to resource key.
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 anActionForwardinstance describing where and how control should be forwarded, ornullif the response has already been completed.
- Overrides:
- execute in interface DispatchAction
- Parameters:
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
- Returns:
- Describes where and how control should be forwarded.
protected Map getKeyMethodMap()
Provides the mapping from resource key to method name.
- Returns:
- Resource key / method name map.