Date: 2004-09-23T23:18:17 Editor: MichaelMcGrady <[EMAIL PROTECTED]> Wiki: Apache Struts Wiki Page: StrutsCatalogFiveMultipleButtonSolutions URL: http://wiki.apache.org/struts/StrutsCatalogFiveMultipleButtonSolutions
no comment Change Log: ------------------------------------------------------------------------------ @@ -36,6 +36,9 @@ 6.2 SOLUTION THREE: ButtonTagUtil Code ----------------- SOLUTION THREE 7. ButtonForm 7.1 Discussion +7.1.1 Only One Button Object (Immediately Destroyed) +7.1.2 Button Command Determined by Button Name and not getX() or getY() +7.1.3 Clean Up and Reset of the Action Form Occasioned by getX() or getY() 7.2 SOLUTION FOUR: ButtonForm Code --------------------- SOLUTION FOUR 8. Button 8.1 Discussion @@ -44,6 +47,10 @@ 10 Comments (Peanut Gallery) 11 Author 12 Readers Favorites +12.1 Niall Pemberton's Links +12.1.1 Link A +12.1.3 Link B +12.2 Let's Hear from You }}} == Universal Button Solutions == @@ -286,7 +293,7 @@ } }}} -== (new) DispatchAction == +== (new) DispatchAction (Called "SimpleDispatchAction" on the Struts Lists) == === Discussion === @@ -449,7 +456,7 @@ === 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. +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. This solution is completely superior to any of the uses of reflection through ActionForms with button objects. === SOLUTION THREE: ButtonTagUtil Solution Code === {{{ @@ -477,7 +484,19 @@ <input type='image' name='delete' src='delete.gif'> }}} === Discussion === -This solution is for <input type='image'> only. The other cases, of course, do not pose special problems with determining which button was clicked. This solution is superior to the Button solution which follows because only one button object has to be created. If you use buttons for navigation extensively within large forms, this because crucial. +This solution is for <input type='image'> only. THIS SOLUTION IS FAR SUPERIOR TO ImageButtonBean for lots of reasons. Remember that if we have "update" as the name, ImageButtonBean, a solution I used for a long time, finds out that "update" is the command because it determines that the result of getting the following by refection is not null: if(new ImageButtonBean().getUpdate().getX() != null). This is clearly not a good idea, because we should just take the value of "update" used to call getUpdate() and be done with it. However, if you just have to use buttons, the following solution is much more sophisticated. This solutions has several advantages to ImageButtonBean. They are: + +==== Only One Button Object ==== +There is only one button object created and it is sent for garbage collection immediately upon being created. +==== The Button Command is Determined Prior to Calling getX() or getY() ==== +The use of "update" to call getUpdate() determines the command to use without using the getX() or getY(). You do not have to check for nulls, etc. +==== The "Free" Use of .x for getX() or .y for getY() is Used for Clean Up and Resetting the ActionForm ==== +The occurence of getX() or getY() is used as the basis for cleanup and resetting the form. + +So, while button solutions are poor in general (too heavy, too slow, too over-engineered) this is better than the existing solutions. + +This solution is superior to the Button solution which follows and is recommended, apparently, by Niall, because only one button object has to be created. If you use buttons for navigation extensively within large forms, this because crucial. + === SOLUTION FOUR: ButtonForm Code === {{{ public class ButtonForm @@ -521,6 +540,7 @@ This solution, too, is only for <input type='image'> === Discussion === This solution is as objectionable to me as (old) DispatchAction in Struts and its progeny, MappingDispatchAction and LookupDispatchAction. However, it is the first solution I proposed on this wiki, so I am putting it in here as a quasi-historical brain matter for those with quasi-hysterical brain matter. + === SOLUTION FIVE: Button Code === First we have the button: {{{ @@ -630,5 +650,5 @@ Open Source Struts Extension [http://kenfitzpatrick.dnsalias.org:8080/imageButtonBeanManager Image Button Bean Manager] -''**This solution is, I would suggest, over-engineered. However, there is one thing about this solution I really, really, really like. That thing is that it creates an extension to struts rather than trying to be part of struts itself. This is the way to go, in my opinion. I admire this restraint and good sense. And, who knows, maybe I am wrong about this solution. I don't think so, but the nice things about extensions is that it leaves everyone a choice rather than having to either do triage to the struts application or having to accept solutions you don't like. -- Michael !McGrady'' +''**This solution is, I would suggest, over-engineered. However, there is one thing about this solution I really, really, really like. That thing is that it creates an extension to struts rather than trying to be part of struts itself. This is the way to go, in my opinion. I admire this restraint and good sense. And, who knows, maybe I am wrong about this solution. I don't think so, but the nice things about extensions is that it leaves everyone a choice rather than having to either do triage to the struts application or having to accept solutions you don't like. Unfortunately, this solution not only embraces the difficulties inherent in ImageButtonBean but also combines that with DispatchAction and its progeny, which have the same problem in a different way. -- Michael !McGrady'' === Let's Hear From You Too === --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]