I have written my own abstract base action which looks up and invokes a
method on the action class using reflection (like DispatchAction). The
difference is that I am looking for a match between any of the request
parameters and a method name. This way I can have many submit buttons on a
form, each with a different name (using the "property" attribute of
<html:submit>). The name is used to look-up the method and the buttons are
I18N ready. I got the idea from the FindForwardAction by Struts Scaffold.


-----Original Message-----
From: Rick Reumann [mailto:[EMAIL PROTECTED] 
Sent: Thursday, September 09, 2004 7:34 PM
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: Trying to come up with a Mapping-Dispatch combo Action

Not sure which list this question/topic really belongs on so posting to 
both. (I'm bringing it up on the dev list because I'm thinking maybe the 
base MappingDispatchAction could/should be modified).

Some design background. I like to keep related tasks belonging in one 
Dispatch Action class (flavor to be discussed). This is a typical 
approach, yet one of the problems is desided on the type of 
DispatchAction ... keep it DispatchAction or use one of the subclasses 
LookupDispatch or MappingDispatch.

First off I really don't like the LookupDispatchAction. I've used it 
extensively in a large application and it becomes a real pain. It 
becomes really ugly to use when you start having some generic button 
names that you reuse for different things. For example a changing 
requirment was that we ended up having to use a button called "Ok" a lot 
(I know stupid). So sometimes "Ok" would submit to the same 
LookupDispatchAction but would need to access different methods. You 
end up then having to create 'fake' button names in your resources file 
just so the LookupDispatchAction can work correctly. Maintenance of the 
LookupDispatch can be a pain also. Anyway...

Until the MappingDispatchAction, I've been relatively content with using 
a standard DispathAction. What I like about the MappingDispatchAction is 
that it works really nicely for links - you don't have to append a 
dispatch parameter name to the URL. It's also nice for typical forms 
since you don't have to provide a hidden dispatch parameter on the page.

The only problem I'm running into it is when you have a form with more 
than one button and each button should call a different dispatch method. 
I haven't really figured out a good way to work this out with the 
MappingDispatchAction.  I think trying to change the form's action 
attribute using JavaScript will be ugly (assuming it can even be done, 
I've never tried it). The only solution I can think of at the moment 
would be to override the getMethodName method of MappingDispatch and 
provide an extra mapping in your config where the parameter would change 
to something like parameter="dispatchMethod"

The overridden getMethodName might look like

protected String getMethodName(
         ActionMapping mapping,
         ActionForm form,
         HttpServletRequest request,
         HttpServletResponse response,
         String parameter)
         throws Exception {
        
        if( "dispatchMethod".equals( parameter ) {
                parameter = request.getParameter(parameter);
        }
         return parameter
     }

This would allow you to use the MappingDispatchAction like a 
DispatchActoin when needed. The only caveat is you would have to make 
sure the if statement in the above is what you wanted. (Probably better 
to pull the parameter name "dispatchMethod" from a properties file or 
constants class).

Maybe there is a much better way to accomplish what I'm concerned with?

-- 
Rick


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

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

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

Reply via email to