Preface

There were few solutions to buttons not long ago. So, this page should be an embassment of riches in some sense. I am going to talk straight on this page, so those with faint hearts and a desire to mince words to save souls should look elsewhere. This is business to me, not a club.

LookupDispatchAction: COLD

First, let's talk about that labyrinth, the LookupDispatchAction in Struts. The actual process of coding and using this class is somewhat unsettling. If we forget that there were few good solutions to multiple images in forms until recently, we have to wonder "What were they thinking?". This is certainly a very clever solution. But, today, I think we should realize it is just off on all counts. It is too heavy, too convoluted, too coupled, just too many "too"s!

Forget for the moment what it takes to code this solution. Forget also for the moment that this solution conflates two very different issues, viz, using reflection to call a method and finding out what method is called. Take a look at what this solution requires to run. This is insanity in the present light of coding.

When a call is made to a use of this class, this is what happens when a "delete" is called which reads "Delete It" on the page.

Don't forget you had to code and to coordinate all of the labyrinth we just followed. Make a mistake in that tortured path, and things fall down. Imagine what this takes to maintain.

Let's turn to a simpler and better solution: the New DispatchAction class.

(new)DispatchAction for Buttons: COOL!

We can get the same result we just got by making the original name attribute (property attribute for Struts) be "delete.x" instead of "button.delete" and code a simple "for loop" to get the request parameter that ends in ".x". Honest. That is all our new DispatchAction does. Nothing else is required. No configuration. No coding the LookupDispatchAction map. No using the ApplicationResources.properties file. No creating a reverse lookup map. No using a reverse lookup map. And so on and so on and so on. This is what the new DispatchAction class does. I recommend it.

DispatchUtil for Buttons: WAY COOL!

Following the suggestion of Hubert Rabago, we can remove the code for the DispatchAction from the Action classes altogether. This was, I thought, an excellent idea, so we can use DispatchUtil to do exactly that.

ImageTagUtil for Buttons: HOT, BABY!

We can complete decouple our solution from Struts by using the ImageTagUtil solution. Note that if you want to have reflection, you can still code that in your action and get the method lookup independently, as we do, from ImageTagUtil. Or, you can feed the results of this to the old DispatchAction class.

TODO: Discuss the Button Object Solutions and Include Mapping and Lookup Solutions