Uploaded image for project: 'Struts 1'
  1. Struts 1
  2. STR-2365

DispatchAction method invocation refactoring

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • Nightly Build
    • 1.4.x
    • Extras
    • None
    • Operating System: Windows XP
      Platform: PC
    • 33573

    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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jmenard.dev@gmail.com Jason Menard
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: