Another way is to override some methods in MountedMapper (thus creating your AnotherPageMapper or something like that).

Methods of interest:

- getCompatibilityScore(): should only return 1 if the url starts with "b" or "c"
See the default MountedMapper implementation, you could simply say:

if( urlStartsWith(request.getUrl(), "b") || urlStartsWith(request.getUrl(), "c") {
    return 1;
} else {
    return 0;
}

This will make sure that your mapper only handles "/b" and "/c". You can still mount it at "/${param}" so it automatically puts the b or c in the PageParameters upon decoding, and puts it in the url upon encoding.

Then simply call (in webapp.init()):

mount(new AnotherPageMapper("/${param}"));

This will add your mapper before all others, thus making sure it is checked before others on encoding and decoding requests.

Op 6-11-2011 19:02, schreef heikki:
hi,

thanks for your explanation. As I want to restrict the possible paths to
AnotherPage to /b and /c and not /xyz, I went for the IRequestMapper
implementation.

I now have an implementation that seems to work perfect, but I'm afraid it's
not thread-safe and I'm not sure if I've understood things correctly. So
please, if you could help me answer the following questions ?

I need to return different URLs from mapHandler() for AnotherPage and for
any other URLs I have in my application. This is because I need the "b" or
"c" as PageParameter to AnotherPage, but it should not happen for other
URLs. So I implemented IRequestMapper such that it wraps the default
RootRequestMapper to be used for all requests except /b and /c, which are
handled by a different IRequestMapper that uses a path variable. In my
Application:

        setRootRequestMapper(new RootRequestMapper(getRootRequestMapper(),
new MountedMapper("/${param}", AnotherPage.class)));

Then in my IRequestMapper implementation, in mapRequest() the request url
segments are checked and if it's /b or /c, use the second one.

To get things to work with the correct URL for both cases, I also check in
mapHandler() which IRequestMapper should return the URL. However I found no
way to remember which case (/b, or anything esle) is being handled between
the mapRequest and mapHandler() methods, so I stored this in a class
variable. This is what I think is not thread-safe.

Please see my implementation here http://pastebin.com/h0rhtFLz.

Surely there's a better of way dealing with this ?

thank you and kind regards
Heikki Doeleman

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3996292.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to