Date: 2004-09-19T07:31:49
Editor: MichaelMcGrady <[EMAIL PROTECTED]>
Wiki: Apache Struts Wiki
Page: StrutsCatalogDispatchUtil
URL: http://wiki.apache.org/struts/StrutsCatalogDispatchUtil
no comment
Change Log:
------------------------------------------------------------------------------
@@ -1,22 +1,28 @@
##language:en
== Table of Contents ==
{{{
-1. Table of Contents
-2. Universal Button Utility for Struts
-3. Uses
-3.1 Mulitiple Image Tags
-3.2 Link Tags
-3.3 Submit Tags
-3.4 File Browse Tags
-3.5 Button Tags
-3.6 struts-config.xml Uses
-3.6.1 MappingDispatchAction
-3.6.2 LookupDispatchAction
-4. Code
-5. Discussion
-5.1 Future Expansion
-5.2 Links
-6. Comments
+1 Table of Contents
+2 DispatchUtil or (new) DispatchAction: Universal Button Solution for Struts
+3 Uses
+3.1 Action Class COde
+3.2 Mulitiple Image Tags
+3.3 Link Tags
+3.4 Submit Tags
+3.5 File Browse Tags
+3.6 Button Tags
+3.7 struts-config.xml Uses
+3.7.1 MappingDispatchAction
+3.7.2 LookupDispatchAction
+4 DispatchUtil Code
+5 SimpleDispatchAction
+5.1 Discussion
+5.2 SimpleDispatchAction Code
+6 Solution for Tags without Struts
+6.1 Discussion
+6.2 ButtonTagUtil Code
+7 Links
+8 Comments (Peanut Gallery)
+
}}}
== Universal Button Utility for Struts ==
@@ -29,6 +35,14 @@
'''N.B. the uses of "dispatch".''' If you do not like using "dispatch", then you can
rewrite the code in the getMethodName(...) method. Essentially, you will need to
replace ".dispatch" with something else in the tag names which you can identify in the
enumeration. You have to use a suffix with this logic. But, if you want a prefix,
e.g. "dispatch.update" or "method.update", then you will have to change the logic too.
Suffix logic seems to best fit the existing methods in String. Otherwise, I would
have used a prefix. You may want to anyway.
+=== Action Class Code to Use ===
+
+In all the following tag uses, you use the Action class code in execute(...) or
process(...) as given directly below.
+
+{{{
+ ActionForward = forward = new
DispatchUtil().dispatch(this,mapping,form,request,response);
+}}}
+
=== Multiple Image Tags ===
Multiple image tags are the primary reason for this class. Integrating this into a
common solution is the difficulty.
@@ -247,13 +261,37 @@
}
}}}
-== Discussion ==
+== SimpleDispatchAction ==
-All this means for you MappingDispatchAction and LookupDispatchAction users is that
where you used some value for the method in your action-mapping such as update, you
now have to use update.dispatch. If you override the method getMethodName( . . . )
and, instead of ''methodName =
paramProperty.substring(0,paramProperty.indexOf('.'));'' use ''methodName =
paramProperty'', you won't have to make any changes. If you want to avoid the use of
struts-config.xml altogether, you can. DispatchUtil really replaces not only
MappingDispatchAction, LookupDispatchAction and DispatchAction but also the necessity
those classes occasioned of using the parameter property of ActionMapping.
+=== Discussion ===
-=== Future Expansion ===
+=== Code ===
+
+== Solution for Tags without Struts ==
+
+=== Discussion ===
+
+You can use the same strategy to determine what button tag has been clicked without
employing Struts. The best way to do this, in my opinion, in the following solution.
+
+=== Code ===
+{{{
+public class ButtonTagUtil {
+ public static String getName(HttpServletRequest request) {
+ String methodName = null;
+ String buttonValue = null;
+ Enumeration enum = request.getParameterNames();
+ while(enum.hasMoreElements()) {
+ buttonValue = (String)enum.nextElement();
+ if(buttonValue.indexOf(".dispatch") >= 0) {
+ methodName = buttonValue;
+ break;
+ }
+ }
+ return methodName.substring(0,methodName.indexOf('.'));
+ }
+}
+}}}
-I put this up quickly to get rid of the mess that had been made of a previous
submission. I will add to this Monday, Sept. 19th, if not sooner. Weddings this
weekend.
=== Links ===
@@ -266,6 +304,8 @@
StrutsCatalogHidingImagesAndOtherResourcesUnderWEBINF
StrutsCatalogMappedBeans
+
+
== Comments (Please Put Comments Here) ==
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]