Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-3090

The ServletUrlRenderer should use the current action / namespace as a default in #renderUrl

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.6
    • Fix Version/s: 2.1.8
    • Component/s: Core Actions
    • Labels:
      None
    • Environment:

      Struts 2.1.6

    • Flags:
      Patch

      Description

      So, here is a bit of a background on the why of that bug.

      I' m working for the canadian governement, and there is a strong need to internationalize applications to be english and french. That goes as far as bilinguifying the URLs. So the url shouldn't be inbox.action but inbox-reception.action if the locale is English or reception-inbox.action if the locale is French. So, of course, it's a nightmare, but hey, that's what make the job interesting

      Anyway, my approach to enable those weird urls is to use a custom ActionMapper. Our actions are actually named after their english names, and the action mapper is adding the French part correctly, and stripping it out when trying to find the right ActionMapping. That's working fine (after some tweaking of the Locale, but nothing really important).

      So where my issue kicks in is that for bilinguilism we have a link on each page using a <s:url /> without any actions, so that it redirects to the current page (with of course a different request_locale).

      Now, the thing that happens when we click the link is that the locale changes, and the url of the page changes. My understanding was that in this case, s:url would use the current namespace and action to generate the actual url. After reading through the code, that's the behaviour in ServletUrlRenderer#renderFormUrl, but ServletUrlRenderer#renderUrl is just recycling the current URL hoping it will still work. Actually that's not working in my case, as the URL changes after the Locale switched. So I'd like for #renderUrl to use the current action / namespace, instead of going for a wild guess based on the current URL.

      In most cases, that doesn't make a difference, as the same page usually have the same URL. However, it's not the same URL generated in my case, and I think the behaviour of ServletUrlRenderer is quite unexpected.

      I'll try to provide a patch ASAP.

        Attachments

        1. WW-3090-patch.txt
          2 kB
          Denis Cabasson
        2. ww-3090-unit-test.patch
          0.9 kB
          Wes Wannemacher
        3. WW-3090-testCase.diff
          3 kB
          Denis Cabasson
        4. WW-3090-patch-2.diff
          2 kB
          Denis Cabasson
        5. WW-3090-test-2.diff
          7 kB
          Denis Cabasson

          Issue Links

            Activity

              People

              • Assignee:
                wesw@wantii.com Wes Wannemacher
                Reporter:
                dcabasson Denis Cabasson
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: