Date: 2004-09-17T00:25:47 Editor: MichaelMcGrady <[EMAIL PROTECTED]> Wiki: Apache Struts Wiki Page: StrutsCatalogSimpleDispatchAction URL: http://wiki.apache.org/struts/StrutsCatalogSimpleDispatchAction
no comment Change Log: ------------------------------------------------------------------------------ @@ -268,14 +268,22 @@ String methodName = null; String buttonValue = null; String parameter = mapping.getParameter(); - if((parameter != null) && (parameter.endsWith(".x"))) { - methodName = parameter.substring(0,parameter.indexOf('.')); + + if((parameter != null) && (parameter.startsWith("method."))) { + methodName = parameter.replaceFirst("method.",""); } else { Enumeration enum = request.getParameterNames(); while(enum.hasMoreElements()) { buttonValue = (String)enum.nextElement(); - if(buttonValue.endsWith(".x")) { - methodName = buttonValue.substring(0,buttonValue.indexOf(".x")); + if(buttonValue.startsWith("method.")) { + methodName = buttonValue.replaceFirst("method.",""); + if(methodName.endsWith(".x")) { + methodName = methodName.replaceFirst(".x",""); + } + if(buttonValue.endsWith(".y")) { + methodName = methodName.replaceFirst(".y",""); + } + break; } } } @@ -373,18 +381,19 @@ ---- -On this we differ. I think the version of SimpleDispatchAction I posted does exactly the same as you're version (caveat requires slight modification to DispatchAction) but does't bloat the code base by duplicating the majority of whats already in DispatchAction. Fundamentally all these things, including SimpleDispatchAcion, do the same thing (i.e. use reflection to execute a specified method) and only differ slightly code-wise in how they determine the method name. +On this we differ. I think the version of !SimpleDispatchAction I posted does exactly the same as you're version (caveat requires slight modification to !DispatchAction) but does't bloat the code base by duplicating the majority of whats already in !DispatchAction. Fundamentally all these things, including !SimpleDispatchAcion, do the same thing (i.e. use reflection to execute a specified method) and only differ slightly code-wise in how they determine the method name. -On the suggestion of factoring out all this code into RequestUtils, I have the following comments: +On the suggestion of factoring out all this code into !RequestUtils, I have the following comments: - * All these static utility classes provide a headache because you can't override their static methods if you want to modify their behaviour. RequestUtils is just such a case - if RequestUtils was refactored to be just a facade to a bean (in the way BeanUtils has been) where you can set a custom instance to use then it would resolve this. But as it stands these kind of things are a pain - especially in this kind of case where alot of the code is the same and you just want to change small parts of the behaviour. + * All these static utility classes provide a headache because you can't override their static methods if you want to modify their behaviour. !RequestUtils is just such a case - if !RequestUtils was refactored to be just a facade to a bean (in the way !BeanUtils has been) where you can set a custom instance to use then it would resolve this. But as it stands these kind of things are a pain - especially in this kind of case where alot of the code is the same and you just want to change small parts of the behaviour. - * Currently DispatchAction only does the reflection to get the methods once and then caches them in a Map - moving this into RequestUtils would mean it would have to use reflection each time the method is called. + * Currently !DispatchAction only does the reflection to get the methods once and then caches them in a Map - moving this into !RequestUtils would mean it would have to use reflection each time the method is called. -I do like Hubert's suggestion factoring the code out of Action altogether and not having to inherit from a specific super class. I have put together a ActionDispatcher class and attached the code to a bug here: +I do like Hubert's suggestion factoring the code out of Action altogether and not having to inherit from a specific super class. I have put together a !ActionDispatcher class and attached the code to a bug here: [http://issues.apache.org/bugzilla/show_bug.cgi?id=31270 Bug 31270] '''Niall Pemberton''' ---- +'''Unfortunately, Niall, you assumed for some reason I was talking about your code. I was not talking about your code. Notice that I did not subclass DispatchAction in SimpleDispatchAction so there could have been no code bloat. In fact, I did not subclass DispatchAction because I don't like the code bloat in that Action. I was talking about your understanding of this class. I wish you would slow down and see what is going on before making all these decisions. I suppose calmer reflection will eventually prevail but presently you are doing things while clearly misapprehending what is going on with this class. You might take some pause at that statement, since I am the author of the class in the frist instance. However, as I said, time will tell. I think I know my class alright.''' --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]