You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andreas Lundblad <an...@gmail.com> on 2017/04/02 08:19:53 UTC
Catch-all URL mapping logic
Searched like crazy without finding any documentation on this...
I would like to maintain functionality of all my currently mounted pages
and resources.
In addition to this, I would like to have a "catch all" mapping logic that
picks up urls like
http://www.example.com/product-A.html
http://www.example.com/product-B.html
...
And if my logic doesn't find "product-X" in the database, it should fall
through to the 404-page.
Some products gets mapped to ProductPage.class, others get mapped to
OtherProductPage.class.
Further more I would like these links to be bookmarkable, and that
parameters gets appended with the usual ?foo=bar
I'm on Wicket 6.24.
cheers,
Andreas Lundblad
Re: Catch-all URL mapping logic
Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Apr 3, 2017 at 10:49 PM, Andreas Lundblad <
andreas.lundblad@gmail.com> wrote:
> Excellent. Big thanks! (For any future reader, I needed to wrap the page in
> a PageProvider in the return statement.)
>
Great!
I've added few convinience constructors to RenderPageRequestHandler in
Wicket 8.x!
>
> I also managed to render nice corresponding URLs for
> BookmarkablePageRequestHandler in the mapHandler method.
>
> I then used the code posted at [1] to avoid redirects and keep the pretty
> URLs in the address bar.
>
> [1] http://stackoverflow.com/a/27827875/276052
>
>
> On Mon, Apr 3, 2017 at 9:02 AM, Martin Grigorov <mg...@apache.org>
> wrote:
>
> > Hi,
> >
> > You can use a custom root request mapper!
> >
> > In YourApplication#init():
> > old = application.getRootRequestMapper()
> > application.setRootRequestMapper(new CustomRequestMapper(old))
> >
> > In CustomRequestMapper#mapRequest() first use 'old' to try to return
> > IRequestHandler. If it returns null then use request.getUrl() and
> > request#getQueryParameters() to try to find a product in your DB.
> > If you have a match then return RenderPageRequestHandler(new
> > ProductPage(product))
> >
> >
> > Martin Grigorov
> > Wicket Training and Consulting
> > https://twitter.com/mtgrigorov
> >
> > On Sun, Apr 2, 2017 at 10:19 AM, Andreas Lundblad <
> > andreas.lundblad@gmail.com> wrote:
> >
> > > Searched like crazy without finding any documentation on this...
> > >
> > > I would like to maintain functionality of all my currently mounted
> pages
> > > and resources.
> > >
> > > In addition to this, I would like to have a "catch all" mapping logic
> > that
> > > picks up urls like
> > >
> > > http://www.example.com/product-A.html
> > > http://www.example.com/product-B.html
> > > ...
> > >
> > > And if my logic doesn't find "product-X" in the database, it should
> fall
> > > through to the 404-page.
> > >
> > > Some products gets mapped to ProductPage.class, others get mapped to
> > > OtherProductPage.class.
> > >
> > > Further more I would like these links to be bookmarkable, and that
> > > parameters gets appended with the usual ?foo=bar
> > >
> > > I'm on Wicket 6.24.
> > >
> > > cheers,
> > > Andreas Lundblad
> > >
> >
>
Re: Catch-all URL mapping logic
Posted by Andreas Lundblad <an...@gmail.com>.
Excellent. Big thanks! (For any future reader, I needed to wrap the page in
a PageProvider in the return statement.)
I also managed to render nice corresponding URLs for
BookmarkablePageRequestHandler in the mapHandler method.
I then used the code posted at [1] to avoid redirects and keep the pretty
URLs in the address bar.
[1] http://stackoverflow.com/a/27827875/276052
On Mon, Apr 3, 2017 at 9:02 AM, Martin Grigorov <mg...@apache.org>
wrote:
> Hi,
>
> You can use a custom root request mapper!
>
> In YourApplication#init():
> old = application.getRootRequestMapper()
> application.setRootRequestMapper(new CustomRequestMapper(old))
>
> In CustomRequestMapper#mapRequest() first use 'old' to try to return
> IRequestHandler. If it returns null then use request.getUrl() and
> request#getQueryParameters() to try to find a product in your DB.
> If you have a match then return RenderPageRequestHandler(new
> ProductPage(product))
>
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Sun, Apr 2, 2017 at 10:19 AM, Andreas Lundblad <
> andreas.lundblad@gmail.com> wrote:
>
> > Searched like crazy without finding any documentation on this...
> >
> > I would like to maintain functionality of all my currently mounted pages
> > and resources.
> >
> > In addition to this, I would like to have a "catch all" mapping logic
> that
> > picks up urls like
> >
> > http://www.example.com/product-A.html
> > http://www.example.com/product-B.html
> > ...
> >
> > And if my logic doesn't find "product-X" in the database, it should fall
> > through to the 404-page.
> >
> > Some products gets mapped to ProductPage.class, others get mapped to
> > OtherProductPage.class.
> >
> > Further more I would like these links to be bookmarkable, and that
> > parameters gets appended with the usual ?foo=bar
> >
> > I'm on Wicket 6.24.
> >
> > cheers,
> > Andreas Lundblad
> >
>
Re: Catch-all URL mapping logic
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
You can use a custom root request mapper!
In YourApplication#init():
old = application.getRootRequestMapper()
application.setRootRequestMapper(new CustomRequestMapper(old))
In CustomRequestMapper#mapRequest() first use 'old' to try to return
IRequestHandler. If it returns null then use request.getUrl() and
request#getQueryParameters() to try to find a product in your DB.
If you have a match then return RenderPageRequestHandler(new
ProductPage(product))
Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov
On Sun, Apr 2, 2017 at 10:19 AM, Andreas Lundblad <
andreas.lundblad@gmail.com> wrote:
> Searched like crazy without finding any documentation on this...
>
> I would like to maintain functionality of all my currently mounted pages
> and resources.
>
> In addition to this, I would like to have a "catch all" mapping logic that
> picks up urls like
>
> http://www.example.com/product-A.html
> http://www.example.com/product-B.html
> ...
>
> And if my logic doesn't find "product-X" in the database, it should fall
> through to the 404-page.
>
> Some products gets mapped to ProductPage.class, others get mapped to
> OtherProductPage.class.
>
> Further more I would like these links to be bookmarkable, and that
> parameters gets appended with the usual ?foo=bar
>
> I'm on Wicket 6.24.
>
> cheers,
> Andreas Lundblad
>