Date: 2004-08-10T20:37:41
Editor: KishoreSenji <[EMAIL PROTECTED]>
Wiki: Apache Struts Wiki
Page: StrutsCatalogMultipleImageButtonsWithNoJavaScript
URL: http://wiki.apache.org/struts/StrutsCatalogMultipleImageButtonsWithNoJavaScript
Making it a DispathAction
Change Log:
------------------------------------------------------------------------------
@@ -125,3 +125,86 @@
-- Michael !McGrady
[EMAIL PROTECTED]
+
+----
+
+Just an extension.
+
+Instead of checking the command value in the execute method of the Action, you can
make your Action extend DispatchAction by overriding the protected dispatchMethod
+
+{{{
+public class TestAction extends DispatchAction {
+ /**
+ * Dispatch to the specified method.
+ * @since Struts 1.1
+ */
+ protected ActionForward dispatchMethod(
+ ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response,
+ String name)
+ throws Exception {
+ return super.dispatchMethod(mapping, form, request, response,
+ ((ButtonForm) form).getCommand());
+ }
+
+ public ActionForward submit(
+ ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response) {
+ return mapping.getInputForward();
+ }
+
+ // Add more methods corresponding to the number of images (submits)
+}
+
+}}}
+'''OR''' by overriding the execute method
+{{{
+public class TestAction extends DispatchAction {
+ public ActionForward execute(
+ ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws Exception {
+
+ // Identify the request parameter containing the method name
+ String parameter = mapping.getParameter();
+ if (parameter == null) {
+ String message =
+ messages.getMessage("dispatch.handler",
mapping.getPath());
+ log.error(message);
+ response.sendError(
+ HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ message);
+ return (null);
+ }
+
+ // Identify the method name to be dispatched to.
+ // dispatchMethod() will call unspecified() if name is null
+ String name = ((ButtonForm) form).getCommand();
+
+ // Invoke the named method, and return the result
+ return dispatchMethod(mapping, form, request, response, name);
+ }
+
+ public ActionForward submit(
+ ActionMapping mapping,
+ ActionForm form,
+ HttpServletRequest request,
+ HttpServletResponse response) {
+ return mapping.getInputForward();
+ }
+
+ // Add more methods corresponding to the number of images (submits)
+}
+
+}}}
+
+If we are dealing with too many images, then it's better to make it an DispathAction
similar to the one illustrated above. One thing to remember is to define a parameter
in the ActionMapping.
+
+Thanks,
+Kishore Senji.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]