Date: 2004-08-10T11:55:12
   Editor: MichaelMcGrady <[EMAIL PROTECTED]>
   Wiki: Apache Struts Wiki
   Page: StrutsCatalogMultipleImageButtonsWithNoJavaScript
   URL: http://wiki.apache.org/struts/StrutsCatalogMultipleImageButtonsWithNoJavaScript

   no comment

Change Log:

------------------------------------------------------------------------------
@@ -1,4 +1,47 @@
-StrutsCatalog: '''Here is one way to take care of that pesky and recurrent problem of 
how to use multiple image buttons in your forms.  This solution will suggest other 
possibilities you might want to code for yourself.'''
+StrutsCatalog: '''Here are TWO WAYS to take care of that pesky and recurrent problem 
of how to use multiple image buttons in your forms.  This solution will suggest other 
possibilities you might want to code for yourself.  Use the one you like best.'''
+
+First, you can merely mine the parameterNames of the request and build your logic in 
your processing of the request accordingly.
+
+{{{
+public final class ButtonCommand {
+  private ButtonCommand() {
+  }
+
+  public final static String getCommand(HttpServletRequest request) {
+    Enumeration enum = request.getParameterNames();
+    String parameterName = null;
+    while(enum.hasMoreElements()) {
+      parameterName = (String)enum.nextElement();
+      if(parameterName.endsWith(".x")) {
+        return parameterName.substring(0,parameterName.indexOf('.'));
+      }
+    }
+    return parameterName;
+  }
+}
+}}}
+
+I do this with the following simple logic in a processing class called by my Action 
class.
+
+{{{
+if (ButtonConstant.SUBMIT.equals(command)) {
+  // do whatever
+}
+}}}
+
+My ButtonConstant class is equally simple.  You might have, for example:
+
+{{{
+public final class ButtonConstant {
+    public static final String CLEAR  = "clear";
+    public static final String DELETE = "delete";
+    public static final String SUBMIT = "submit";
+  private ButtonConstant() {
+  }
+}
+}}}
+
+If you want something more OOP in nature, then the following might be your choice.
 
 The Struts page tags are simple.  If you have buttons you want called "submit" and 
"clear" for example, you would have the following page tags:
 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to