Thank you Erik, the idea is nice, but it does not work ;)

I wanted to implement my own ~ Root Mounting Strategy just when I've
got your email. The idea with overriding getRequestPath sounds good, I
was afraid that I will need to implement my own RequestCycle with
custom logic replacing "path.startWith(mountPath())" part.

Unfortunately your solution doesn't seem to play well with forms. When
using the RootWebRequestProcessor pages using HybridUrlCodingStrategy
work on first get request, but after button submit they are redirected
to "?wicket:..." page and the state of the page is lost (all values of
fields, no validation errors). I have no idea why it works like that
and does it breaks other strategies.

ps. I had to add
<configuration>
  <webAppConfig>
        <contextPath>/</contextPath>
  </webAppConfig>
</configuration>
to the POM to make the example run properly with jetty:run. The
default configuration mount the app on /wicket-rootmount-demo so most
of the links does not work.

Regards,
Krzysztof Kowalczyk

On Wed, Dec 1, 2010 at 1:59 PM, Erik van Oosten <[email protected]> wrote:
> You can try the approach from
> http://blog.jteam.nl/2010/02/24/wicket-root-mounts/
>
> This allows you to install a URL mounter that implements the following
> interface:
>
> interface RootMountedUrlCodingStrategy {
>  boolean accepts(String rawPath);
> }
>
> Regards,
>    Erik.
>
>
> Op 30-11-10 11:21, Krzysztof Kowalczyk wrote:
>>
>> Hi,
>>
>> We have existing urls in a form:
>>
>> /long,and,complex,title,id/new_opinion
>> /long,and,complex,title,id/something
>>
>> or sometimes
>>
>> /long,title/id/new_opinion
>>
>> The links like "/long,and,complex,title" are managed by fast and
>> scalable view, and are stateless. Now we are using Wicket in the same
>> war. It is mounted to "/cms".
>>
>> We are trying to replace forms, that are pure evil in the first
>> technology with wicket based forms. But we need to keep the links
>> untouched.
>>
>> So I created  UrlRewrite (http://www.tuckey.org/urlrewrite/) rules:
>>
>> <urlrewrite use-query-string="true">
>>
>> <rule>
>>        <from>^/(.*),(\d+)/new_opinion$</from>
>>        <to>/cms/new_opinion/id/$2/url/$1</to>
>> </rule>
>>
>> <rule>
>>        <from>^/(\?wicket.*)</from>
>>        <to>/cms/$1</to>
>> </rule>
>> ...
>>
>>
>> I have a wicket page - that is mounted on "/new_opinion" with enhanced
>> HybridUrlCodingStrategy with:
>> - redirectOnBookmarkableRequest = false
>>
>> First rule forwards the request to proper place. Wicket gets the
>> correct requestUri and all the stuff. But the rule does not work if we
>> have redirectOnBookmarkableRequest = true because Wicket constructs
>> wrong urls in ServletWebRequest.getRelativePathPrefixToWicketHandler :
>>
>>                if (!Strings.isEmpty(forwardUrl))
>>                {
>>                        // If this is an error page, this will be /mount or
>> /?wicket:foo
>>                        relativeUrl = forwardUrl.substring(1);
>>                        relativeUrl =
>> relativeUrl.substring(filterPath.length());
>>                }
>>
>> before this fragment Wicket has correct link, after this we get:
>> "g,and,complex,title,id/new_opinion", or errors (sometimes the link is
>> shorter and I get array index out of bounds). If method does not throw
>> exception it returns wrong number of ../ . Unfortunately
>> redirectOnBookmarkableRequest = false does not solve the problem as
>> the second rule catches Wicket that are redirected if they hit
>> bookmarkable page. So this fragment need to be fixed in order to have
>> working bookmarkable links with UrlRewrite.
>>
>> My temporary workaround is custom delegating WebRequest with small hack:
>>
>> public String getRelativePathPrefixToWicketHandler() {
>>        HttpServletRequest httpRequest = getHttpServletRequest();
>>
>>        String forwardUrl =
>> (String)httpRequest.getAttribute("javax.servlet.forward.servlet_path");
>>        final String filterPath =
>> (String)httpRequest.getAttribute(WicketFilter.FILTER_PATH_ATTR);
>>
>>        if (!Strings.isEmpty(forwardUrl))
>>        {
>>                int count = forwardUrl.split("/").length;
>>
>>                String string = "";
>>
>>                for (int i = 1; i<  count; i++) {
>>                        string += "../";
>>                }
>>
>>                return string + filterPath;
>>        }else {
>>                return
>> wrappedReqest.getRelativePathPrefixToWicketHandler();
>>        }
>> }
>>
>> I guess it will not work in all cases though...
>>
>> If there is a different way of doing url rewriting? If not, I consider
>> it a bug in Wicket.
>>
>> Regards,
>> Krzysztof Kowalczyk
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
>
> --
> Erik van Oosten
> http://www.day-to-day-stuff.blogspot.com/
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to