Michael McGrady wrote the following on 9/14/2004 11:04 PM:
Your notes on links confuse me a bit. Let me consider what confuses me and then we can go from there.
FIRST
You said ". . . MappingDispatchAction has . . . a cetnralized place to decide what method is called based on the action name." I understand this to mean that a different method is called for different action names. Is that right? That seems odd, since the MappingDispatchAction is an action. So, if you called a different MappingDispatchAction, you would, presumably, call a different action but the same method name. Is this right? Did you mean to say that?
Well I meant that you could have a mapping /updateUser as your form action parameter but that could relate to any possible dispatch method name you want based on what you decide as the parameter name in the mapping. Typically of course this would niceley correspond to a similar "update" parameter name which would equate to an update method - similar to the example in the java docs on MappingDispatchAction:
<action path="/editSubscription" type="org.example.SubscriptionAction" parameter="edit"> <forward name="success" path="/editSubscription.jsp"/> </action>
So what I meant was that in theory all your links that would go to /editSubscription could easily be changed to go to a different method name simply by changing the parameter name in your struts config mapping. I'll clarify more below...
Suppose that SubscriptionAction is a SimpleDispatchAction subclass. Just put a ".x" after the parameter names, and SimpleDispatchActions do exactly the same thing as your MappingDispatchActions.
You are thinking of changing the mapping so
that the following code <c:url var="url" value="/editSubscription.do"/><a href="${url}">[ editSubscription]</a> does something other than edit a subscription. This is not, I would suggest, a good idea.
What normally you would want when you want a link to initiate a different command/operation is to have the link exhibit that change on the page. The beauty of SimpleDispatchAction is that you can do this and change nothing else. (You also only have to have one action mapping rather than the melange of mappings usually required by a MappingDispatchAction.) If you want to create rather than edit a subscription, in SimpleDispatchAction you go from:
<c:url var="url" value="/subscription.do?edit.x=edit"/><a href="${url}">[ edit]</a>
to
<c:url var="url" value="/subscription.do?create.x=create"/><a href="${url}">[ create]</a>
If you don't want to do this, you can use a variable for the value of the url. I do that all the time. I hard code very, very little on a page.
Does this answer make any sense to you?
Yes it makes sense and it is very nice. I actually like your solution a lot.
The one thing you mention though as not a good idea in my solution, I still see as a potential good idea, but maybe a better example would help:
Imagine you designed an application and you had a link..
<c:url var="url" value="/getUsers.do"/><a href="${url}">[ Get Users ]</a>
In the beginning of this application I assumed the client would always want to see all users so I created a MappingDispatchAction method (or regular DispatchAction method) called "getUsers(...)" which returned a list of all users in the company and put them in scope for the resulting page to display.
Imagine also that I had to put this link in a bunch of places within the web application.
Later on I'm told by the project manager that "we really need the client to be brought to a search criteria screen to filter out the number of users returned when trying to display users." I don't want to have to touch all the links in the application AND I also want to keep my "getUsers" dispatch method as is (maybe somewhere else I'll need it so I want to keep it around and not rename or alter it). What I need now because of the new requirments is a way to get to a search screen first when the user clicks on the 'Get Users" links.
For me this is very easy to change. I simply change the parameter in the struts-config for 'getUsers' to something like "setUpUserSearch" which would call that setUpUserSearch method and forward me to that search screen. (After submit I'd be brought to my search results).
Wouldn't you initial link in this scenario have looked something like:
<c:url var="url" value="/getUsers.do?getUsers.x=getUsers"/><a href="${url}">[ Get Users ]</a>
If so, wouldn't all of them need to altered if you wanted to go to 'setUpSearch' instead? (Remember I still want to keep getUsers method around for possible other parts of the application so I don't want to have to change that dispatch method behavior).
I admit that this type of stuff won't happen that often. Your approach looking for .x is pretty cool. It's similar (I think:) to what I was planning on doing sort of with my MappingDispatchAction-combo where I over-rode the getMethodName method to something like...
protected String getMethodName(..) {
if( "dispatchMethod".equals( parameter ) { parameter = request.getParameter(parameter); } return parameter }
which would allow me to simply pass in a request parameter named dispatchMethod and this would override the use of the parameter name defined in the struts-config mapping corresponding to the method to call. For example...
<c:url var="url" value="/getUsers.do"> <c:param name="dispatchMethod" value="fooBar"/> </c:url> <a href="${url}">[ Get Users ]</a>
The above would act as your typical DispatchAction. (If I really go with this solution I wouldn't hard-code the "dispatchMethod" String)
Ok good night.. i'm way too tired:) Sorry if this was unclear.
-- Rick
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]