wicket-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bas Gooren <...@iswd.nl>
Subject Re: Mounting page to mutliple urls with different pageparameter
Date Fri, 04 Nov 2011 17:54:00 GMT
Well, the simplest solution would be:

- set Index.class as your homepage (through the corresponding method in 
your application class)
- use mount(new MountedMapper("/${param}", AnotherPage.class));

that should at least get "/b" and "/c" working. Unfortunately (?) that 
will also allow /xyz and /abc to be routed to AnotherPage.class;

If you do not want the latter, you need to do what Martin suggested: 
build your own implementation of IRequestMapper. Return 1 (or 
Integer.MAX_VALUE) for getCompatibilityScore() when the first segment is 
"b" or "c" and 0 otherwise.
Mount this new request mapper as the root request mapper, and only do so 
once. There is no need to mount it more than once, since all requests 
are routed to the same page class.

Op 4-11-2011 15:15, schreef heikki:
> hi,
>
> thanks for your hints, but still I didn't get it to work. I have a
> RootRequestMapper that extends MountedMapper, and it overrides mapRequest()
> like so
>
>      @Override
>      public IRequestHandler mapRequest(Request request) {
>          List<String>  segments = request.getUrl().getSegments();
>          if(CollectionUtils.isEmpty(segments)) {
>              System.out.println("mapRequest to Index page");
>              return new RenderPageRequestHandler(new
> PageProvider(IndexPage.class));
>          }
>          else {
>              System.out.println("mapRequest to Another page");
>              return new RenderPageRequestHandler(new
> PageProvider(AnotherPage.class, new PageParameters().add("param",
> segments.get(0))));
>          }
>      }
>
> Now, with this in Application:
>
>         mount(new RootRequestMapper("/", Index.class));
>         mount(new RootRequestMapper("b", AnotherPage.class));
>         mount(new RootRequestMapper("c", AnotherPage.class));
>
> Result: / ends up correctly in IndexPage, but /b and /c end up serving an
> empty HTML page (?!).
>
> If I only put this in Application (without the root mapping)
>
>         mount(new RootRequestMapper("b", AnotherPage.class));
>         mount(new RootRequestMapper("c", AnotherPage.class));
>
> Result: / serves an empty page, and /b does end up in AnotherPage, but
> renders this in the address bar: /c?param=c (again, replacing b with c, and
> now adding the param as a visible url parameter).
>
> Then I tried using a 'wildcard' like this
>
>          mount(new RootRequestMapper("/", Index.class));
>          mount(new RootRequestMapper("/${param}", AnotherPage.class));
>
> Result: / serves correctly the index page, /b serves an empty HTML page.
>
> In all cases, the System.outs in my RootRequestMapper correctly say either
> "to Index page" or "to Another page" -- even in those cases above where a
> blank HTML page is served, though constructor of said pages is not invoked
> then.
>
> So I guess I'm missing some small but essential detail somewhere .. if you
> would have any further advice, thanks very much, in advance.
>
> Kind regards
> Heikki Doeleman
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3990222.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message