Details
Description
A common pattern in Struts is to apply the template method design pattern to
create a base action for one's application, as discussed in
StrutsCatalogBaseAction in the Struts wiki
(http://wiki.apache.org/struts/StrutsCatalogBaseAction). Occasionally,
developers may wish to use an alternate method signature. While this is no
problem with Action, it is more problematic with DispatchAction and its
subclasses. I would like to propose a minor refactoring of DispatchAction in
order to facilitate this.
The refactoring consists of extracting two lines from dispatchMethod() into a
new method protected call invokeMethod().
The original code from dispatchMethod():
Object args[] =
{mapping, form, request, response};forward = (ActionForward) method.invoke(this, args);
Refactored dispatchMethod():
forward = invokeMethod(mapping, form, request, response, method);
And the new method:
protected ActionForward invokeMethod(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response,
Method method)
throws Exception {
Object args[] = {mapping, form, request, response}
;
ActionForward forward = (ActionForward) method.invoke(this, args);
return forward;
}
Applying this refactoring will allow the developer to more easily extend
DispatchAction in order to allow for alternate method signatures.
I will attach a patch.