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

Allow query strings and anchors when returning forwards from Action

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.3.0
    • 1.3.4
    • Core
    • None
    • Operating System: other
      Platform: Other
    • 36037

    Description

      This was prompted by a recent question on the User's list, although I have
      seen similar questions come up many times...

      At the end of a typical Action, a developer does:

      return mapping.findForward("someForward");

      This will, typically, forward to some JSP. It is sometimes desireable to pass
      parameters to that JSP, or to the next Action if the developer chooses to
      forward to a mapping. It is also sometimes desireable to be able to send an
      anchor along so that the browser will jump to the named anchor on the returned
      page.

      Both of these can be accomplished by "cloning" the returned forward and
      manually setting the path appropriately. However, I believe this is more work
      than it really needs to be. Even though it's not a big deal to do, we've
      probably all done it at some point, it does require a developer to know the
      internals of Struts a little more than they maybe should (i.e., they have to
      understand that a ForwardConfig is frozen and has to be cloned to alter its
      fields), and I believe this modification removes that neccessity.

      The attached patch enables this capability in a more developer-friendly way,
      namely that they can simply append the query string and/or anchor to the
      forward name requested, like so:

      return mapping.findForward("someMapping?myParam=myVal#myAnchor");

      In most cases this will probably be constructed dynamically in the Action, but
      the result is the same.

      The patch affects four classes: RequestProcessor, PerformForward,
      ActionMapping and ActionForward. ActionForward simply has two new fields and
      associated bean methods, "queryString" and "anchor". RequestProcessor and
      PerformForward have identical new code, namely two lines that simply append
      the query string and anchor to the URI forwarded or redirected to.
      ActionMapping is where the more involved (relatively-speaking) changes are,
      but then only in the findForward() method (as well as one new import).

      Attached is also a dirt-simple sample app to demonstrate this working. Should
      just be able to drop it in any container and give it a wirl.

      It is my hope that enough people find this useful (and find no problems with
      it of course!) to warrant being committed for the 1.3 release. I think more
      than a few people will thank us for it

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--ActionRedirect.java
          12 kB
          Frank W. Zammetti
        2. ASF.LICENSE.NOT.GRANTED--ForwardBuilder.java
          9 kB
          Christopher Schultz
        3. ASF.LICENSE.NOT.GRANTED--ForwardBuilderTests.java
          5 kB
          Christopher Schultz
        4. ASF.LICENSE.NOT.GRANTED--NameValuePair.java
          1 kB
          Christopher Schultz
        5. ASF.LICENSE.NOT.GRANTED--queryStringAnchors.patch
          6 kB
          Frank W. Zammetti
        6. ASF.LICENSE.NOT.GRANTED--test.zip
          730 kB
          Frank W. Zammetti

        Activity

          People

            Unassigned Unassigned
            fzammetti@omnytex.com Frank W. Zammetti
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: