Wicket
  1. Wicket
  2. WICKET-4079

Provide new HybridPageParametersEncoder class for backwards compatibility with pre 1.5.x Hybrid URL encoding

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5.1
    • Fix Version/s: 1.5.1
    • Component/s: wicket
    • Labels:
      None

      Description

      Any 1.4 app that has been live for a while would likely have a collection of links pointing to it from external sites on the web. You really want the Wicket 1.5 version of your app to be able to handle any existing hybrid style links without generating an error.

      The links are in the style:

      /myPage/paramName1/paramValue1/paramName2/paramValue2

      When migrating to 1.5, without a 1.4 compatible IPageParametersEncoder implementation, you need to include the full parameter specification in every mount if you want to avoid making changes to each individual Page class that reads parameters. The attached IPageParametersEncoder implementation means that is no longer necessary. All that is needed is to mount your pages as follows:

      mount(new MountedMapper("/myPage/", MyPage.class, new HybridPageParametersEncoder());

      I'm submitting this .java file as a patch so that hopefully it may be included in future 1.5.x versions of Wicket to make it easy to implement backwards compatible URL parameter encoding for other 1.4 migrators.

      This code is based on a suggestion by luniv on StackOverflow here: http://stackoverflow.com/questions/6154430/how-do-i-mimic-hybridurlcodingstrategy-in-wicket-1-5

        Activity

        Hide
        Chris Colman added a comment -

        1.4 compatible hybrid URL implementation of IPageParametersEncoder

        Show
        Chris Colman added a comment - 1.4 compatible hybrid URL implementation of IPageParametersEncoder
        Hide
        Igor Vaynberg added a comment -

        committed as UrlPathPageParametersEncoder

        Show
        Igor Vaynberg added a comment - committed as UrlPathPageParametersEncoder
        Hide
        Chris Colman added a comment -

        Just discovered that decodePageParameters method can cause a problem if a trailing slash is included in the URL

        eg., http://www,mydomain.com/content/home/p/35/

        Here's a patch to fix this:

        • String value = segment.next();

        + // A trailing slash can be seen as an extra segment with a "" value so check
        + // if there is a matching value for this parameter name and ignore it if not
        + if ( segment.hasNext() )
        +

        { + String value = segment.next(); + + parameters.add(key, value); + }
        Show
        Chris Colman added a comment - Just discovered that decodePageParameters method can cause a problem if a trailing slash is included in the URL eg., http://www,mydomain.com/content/home/p/35/ Here's a patch to fix this: String value = segment.next(); + // A trailing slash can be seen as an extra segment with a "" value so check + // if there is a matching value for this parameter name and ignore it if not + if ( segment.hasNext() ) + { + String value = segment.next(); + + parameters.add(key, value); + }
        Hide
        Martin Grigorov added a comment -

        can you provide some unit tests too ?

        Show
        Martin Grigorov added a comment - can you provide some unit tests too ?
        Hide
        Chris Colman added a comment -

        I haven't got any unit tests at this stage but I have thoroughly tested
        in myself. The previous version worked fine so long as no trailing /
        appear. I've tested that this version works without or with a trailing
        slash.

        I'll try to get some unit tests built when I get some spare time but
        that's pretty scarce at the moment.

        compatibility
        ------------------------------------------------------------------------
        -
        https://issues.apache.org/jira/browse/WICKET-4079
        collection
        the
        IPageParametersEncoder
        to
        implement
        a
        http://www.atlassian.com/software/jira

        Show
        Chris Colman added a comment - I haven't got any unit tests at this stage but I have thoroughly tested in myself. The previous version worked fine so long as no trailing / appear. I've tested that this version works without or with a trailing slash. I'll try to get some unit tests built when I get some spare time but that's pretty scarce at the moment. compatibility ------------------------------------------------------------------------ - https://issues.apache.org/jira/browse/WICKET-4079 collection the IPageParametersEncoder to implement a http://www.atlassian.com/software/jira
        Hide
        Martin Grigorov added a comment -

        I added some.
        There were more problems with leading slash and slashes in the middle.

        Show
        Martin Grigorov added a comment - I added some. There were more problems with leading slash and slashes in the middle.

          People

          • Assignee:
            Igor Vaynberg
            Reporter:
            Chris Colman
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development