Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.5.7
    • Fix Version/s: 6.2.0
    • Component/s: wicket
    • Labels:
      None

      Description

      When using the following code to create an absolute url in wicket 1.5.7 from a page class and parameters, there are also duplicate segments in the url. the rendered absolute url is not correct.

      final Url url = RequestCycle.get().mapUrlFor( pageClass, pageParameters );
      final String result = RequestCycle.get().getUrlRenderer().renderFullUrl( url );

      RequestCycle.get().mapUrlFor(..) does not return an "absolute" url (first segment will not be empty).

      See also description in WICKET-4561

      1. quickstart.zip
        34 kB
        Dirk Forchel

        Activity

        Hide
        Martin Grigorov added a comment -

        I've improved the javadoc of #mapUrlFor() methods. Now they describe what is the difference with #urlFor() methods.

        Show
        Martin Grigorov added a comment - I've improved the javadoc of #mapUrlFor() methods. Now they describe what is the difference with #urlFor() methods.
        Hide
        Martin Grigorov added a comment -

        The fix for your app is to replace
        final Url url = getRequestCycle().mapUrlFor( getPageClass(), getPageParameters() );

        with
        final Url url = Url.parse(urlFor( getPageClass(), getPageParameters() ).toString());

        I am not sure how to prevent such error cases. Different methods create different things.

        urlFor() returns url relative to the current one (the baseUrl). It uses mapUrlFor() internally to get the url that the IRequestMapper would create and then relativizes it agains the baseUrl.

        mapUrlFor() returns the plain url that IRequestMapper creates. I'm not sure how useful is it for end users because it returns an url which is relative to the filter path, not against the current url or the context path...

        Show
        Martin Grigorov added a comment - The fix for your app is to replace final Url url = getRequestCycle().mapUrlFor( getPageClass(), getPageParameters() ); with final Url url = Url.parse(urlFor( getPageClass(), getPageParameters() ).toString()); I am not sure how to prevent such error cases. Different methods create different things. urlFor() returns url relative to the current one (the baseUrl). It uses mapUrlFor() internally to get the url that the IRequestMapper would create and then relativizes it agains the baseUrl. mapUrlFor() returns the plain url that IRequestMapper creates. I'm not sure how useful is it for end users because it returns an url which is relative to the filter path, not against the current url or the context path...
        Hide
        Dirk Forchel added a comment -

        Attached you can find the quickstart. The BasePage class generates in the HTML header links to alternative Languages/Locales (just as an example). These links are absolute URLs. With Wicket 1.5.5 the generated links are correct but not with Wicket 1.5.7.

        correct: http://localhost:8080/shop/en/home.html
        wrong: http://localhost:8080/shop/de_DE/shop/en/home.html

        You can switch to different Locales/Languages with the LocaleDropDownChoice added to each page.

        Show
        Dirk Forchel added a comment - Attached you can find the quickstart. The BasePage class generates in the HTML header links to alternative Languages/Locales (just as an example). These links are absolute URLs. With Wicket 1.5.5 the generated links are correct but not with Wicket 1.5.7. correct: http://localhost:8080/shop/en/home.html wrong: http://localhost:8080/shop/de_DE/shop/en/home.html You can switch to different Locales/Languages with the LocaleDropDownChoice added to each page.

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Dirk Forchel
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development