You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Daniele Dellafiore <da...@dellafiore.net> on 2011/10/10 17:48:50 UTC

Mounting external pages to root

Hi.
I have now mounted some internal pages and then all the external are
mounted like:

getRootRequestMapperAsCompound().add(new MountedMapper("cms/${page}",
ExternalPage.class) );

What I'd like is that ALL the URL that are not mounted with an
explicit mapper are automatically redirected to ExternalPage.class,
also keeping the ${page} parameter that I use internally in that page.

There's a nice way to do that?

Thanks.

-- 
Daniele Dellafiore
http://danieledellafiore.net

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


Re: Mounting page to mutliple urls with different pageparameter

Posted by Martin Grigorov <mg...@apache.org>.
No need to extend MountedMapper.
Just implement IRequestMapper and then use
application.setRootRequestMapper(yourMapper)

See how CryptoMapper works.

On Fri, Nov 4, 2011 at 4:21 PM, heikki <tr...@gmail.com> wrote:
> sorry, just saw your reply about pastebin after posting.
>
> Here it is: http://pastebin.com/uRNyxZbV.
>
> Thanks and kind regards
> Heikki Doeleman
>
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3990244.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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Mounting page to mutliple urls with different pageparameter

Posted by heikki <tr...@gmail.com>.
sorry, just saw your reply about pastebin after posting.

Here it is: http://pastebin.com/uRNyxZbV.

Thanks and kind regards
Heikki Doeleman



--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3990244.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


Re: Mounting page to mutliple urls with different pageparameter

Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Nov 7, 2011 at 1:41 PM, heikki <tr...@gmail.com> wrote:
> thanks !
>
> Adding a second IRequestMapper like that, rather than replacing the default
> with a dual-function like I tried above, is so much simpler and works like a
> charm.
>
> That being said, it turns out that it has no effect whether or not I
> override getCompatibilityScore(). See my implementation below. If I do not
> override mapRequest() to check the url and return null, it accepts all URLs
> like /xyz (using Wicket 1.5.2).
>
> In any case, everything works fine now for me. Thanks a lot !
>
> for reference, my code :
>
> in Application:
>
>        mount(new AnotherPageRequestMapper("/${param}", AnotherPage.class));
>
> and the impl:
>
>       import org.apache.wicket.request.IRequestHandler;
>       import org.apache.wicket.request.Request;
>       import org.apache.wicket.request.component.IRequestablePage;
>       import org.apache.wicket.request.mapper.MountedMapper;
>
>       public class AnotherPageRequestMapper extends MountedMapper{
>
>              public AnotherPageRequestMapper(String mountPath, Class<?
> extends IRequestablePage> pageClass) {
>                     super(mountPath, pageClass);
>    }
>
>              public IRequestHandler mapRequest(Request request) {
>                     String url = request.getUrl().toString();
>                     if(url.startsWith("b")) {
>                            return super.mapRequest(request);
>                     }
>                     else {
>                            return null;
>                     }
>              }
>
>              /**
>               * it does not make a difference, in practice, what this
> method returns (?!).

read the documentation of this method to understand what it is for.

>               */
>              public int getCompatibilityScore(Request request) {
>                     String url = request.getUrl().toString();
>                     if(url.startsWith("b")) {
>                            return 1;
>                     }
>                     else {
>                            return 0;
>                     }
>              }
>       }
>
>
>
> kind regards
> Heikki Doeleman
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3998358.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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Mounting page to mutliple urls with different pageparameter

Posted by heikki <tr...@gmail.com>.
thanks ! 

Adding a second IRequestMapper like that, rather than replacing the default
with a dual-function like I tried above, is so much simpler and works like a
charm.

That being said, it turns out that it has no effect whether or not I
override getCompatibilityScore(). See my implementation below. If I do not
override mapRequest() to check the url and return null, it accepts all URLs
like /xyz (using Wicket 1.5.2).

In any case, everything works fine now for me. Thanks a lot !

for reference, my code :

in Application:

        mount(new AnotherPageRequestMapper("/${param}", AnotherPage.class));

and the impl:

       import org.apache.wicket.request.IRequestHandler;
       import org.apache.wicket.request.Request;
       import org.apache.wicket.request.component.IRequestablePage;
       import org.apache.wicket.request.mapper.MountedMapper;

       public class AnotherPageRequestMapper extends MountedMapper{

              public AnotherPageRequestMapper(String mountPath, Class<?
extends IRequestablePage> pageClass) {
                     super(mountPath, pageClass);
    }

              public IRequestHandler mapRequest(Request request) {
                     String url = request.getUrl().toString();
                     if(url.startsWith("b")) {
                            return super.mapRequest(request);
                     }
                     else {            
                            return null;
                     }
              }

              /**
               * it does not make a difference, in practice, what this
method returns (?!).
               */
              public int getCompatibilityScore(Request request) {
                     String url = request.getUrl().toString();
                     if(url.startsWith("b")) {
                            return 1;
                     }
                     else {
                            return 0;
                     }
              }
       }



kind regards
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3998358.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


Re: Mounting page to mutliple urls with different pageparameter

Posted by Bas Gooren <ba...@iswd.nl>.
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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>

Re: Mounting page to mutliple urls with different pageparameter

Posted by heikki <tr...@gmail.com>.
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Mounting page to mutliple urls with different pageparameter

Posted by Bas Gooren <ba...@iswd.nl>.
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
>

Re: Mounting page to mutliple urls with different pageparameter

Posted by heikki <tr...@gmail.com>.
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


Re: Mounting page to mutliple urls with different pageparameter

Posted by Igor Vaynberg <ig...@gmail.com>.
On Fri, Nov 4, 2011 at 6:37 AM, Martin Grigorov <mg...@apache.org> wrote:
> On Fri, Nov 4, 2011 at 3:17 PM, Bas Gooren <ba...@iswd.nl> wrote:
>> The latter problem is logical: your mapping is focused on incoming requests.
>> When wicket renders a link to AnotherPage.class, which url should be
>> generated?
>>
>> My guess is that a request for /b comes in, wicket then checks if the url is
>> valid for AnotherPage.class by generating a url for it, which is /c (*).
>>
>> *) See WebPageRenderer#respond(RequestCycle).
>
> my eyes bleed when I look in this method :-)
>

your eyes only bleed because you didnt have to debug/work with the
analog of this code in 1.4.x. this is a major improvement :)

-igor

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


Re: Mounting page to mutliple urls with different pageparameter

Posted by Bas Gooren <ba...@iswd.nl>.
My eyes too :-)

I was working on absolute urls the other day, and then came along this 
"pearl".
But since you are the one who reported/created WICKET-3347 you've 
enjoyed the sight of this method before :-)

But back on-topic:
The TS should create a single root mapper which maps AnotherPage.class 
and handles encoding/decoding of url properly before handing the request 
off to the rest of the mappers.

TS: Can you link to e.g. pastebin and put the RootMapper you built 
online there?

Op 4-11-2011 14:37, schreef Martin Grigorov:
> On Fri, Nov 4, 2011 at 3:17 PM, Bas Gooren<ba...@iswd.nl>  wrote:
>> The latter problem is logical: your mapping is focused on incoming requests.
>> When wicket renders a link to AnotherPage.class, which url should be
>> generated?
>>
>> My guess is that a request for /b comes in, wicket then checks if the url is
>> valid for AnotherPage.class by generating a url for it, which is /c (*).
>>
>> *) See WebPageRenderer#respond(RequestCycle).
> my eyes bleed when I look in this method :-)
>
>> Simply put: you need to properly handle url generation, too :-)
>>
>> Op 4-11-2011 13:53, schreef heikki:
>>> hello,
>>>
>>> I still find URL mapping to be far from easy. I can't get the following
>>> mapping to work; all advice very much appreciated:
>>>
>>> intented mapping is:
>>>
>>> /                      -->    map to IndexPage.class
>>> /b                    -->    map to AnotherPage.class with pageparameter
>>> param="b"
>>> /c                    -->    map to AnotherPage.class with pageparameter
>>> param="c"
>>>
>>> I tried creating a custom RootRequestMapper but I could not get it to
>>> work.
>>> The closest I've come to achieving the above url mapping is with this in
>>> my
>>> Application
>>>
>>>       protected void init() {
>>>            super.init();
>>>            mount(new MountedMapper("b", AnotherPage.class, new
>>> CustomPageParametersEncoder("b")));
>>>            mount(new MountedMapper("c", AnotherPage.class, new
>>> CustomPageParametersEncoder("c")));
>>>       }
>>>       public Class getHomePage() {
>>>            return IndexPage.class;
>>>       }
>>>
>>> where CustomPageParametersEncoder creates the pageparameter from the url
>>> in
>>> method decodePageParameters().
>>>
>>> What doesn't work here, is that requests to /b are turned into requests to
>>> /c, with pageparameter "c".
>>>
>>> So I end up, when requesting /b, with /c in my browser address bar, and
>>> the
>>> page saying "Hello, c", where I want to end up with /b in my address bar
>>> and
>>> the page saying "Hello, b".
>>>
>>> Your advice is very much appreciated,
>>> kind regards
>>> Heikki Doeleman
>>>
>>> --
>>> View this message in context:
>>> http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3989966.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
>>>
>
>

Re: Mounting page to mutliple urls with different pageparameter

Posted by Martin Grigorov <mg...@apache.org>.
On Fri, Nov 4, 2011 at 3:17 PM, Bas Gooren <ba...@iswd.nl> wrote:
> The latter problem is logical: your mapping is focused on incoming requests.
> When wicket renders a link to AnotherPage.class, which url should be
> generated?
>
> My guess is that a request for /b comes in, wicket then checks if the url is
> valid for AnotherPage.class by generating a url for it, which is /c (*).
>
> *) See WebPageRenderer#respond(RequestCycle).

my eyes bleed when I look in this method :-)

>
> Simply put: you need to properly handle url generation, too :-)
>
> Op 4-11-2011 13:53, schreef heikki:
>>
>> hello,
>>
>> I still find URL mapping to be far from easy. I can't get the following
>> mapping to work; all advice very much appreciated:
>>
>> intented mapping is:
>>
>> /                      -->  map to IndexPage.class
>> /b                    -->  map to AnotherPage.class with pageparameter
>> param="b"
>> /c                    -->  map to AnotherPage.class with pageparameter
>> param="c"
>>
>> I tried creating a custom RootRequestMapper but I could not get it to
>> work.
>> The closest I've come to achieving the above url mapping is with this in
>> my
>> Application
>>
>>      protected void init() {
>>           super.init();
>>           mount(new MountedMapper("b", AnotherPage.class, new
>> CustomPageParametersEncoder("b")));
>>           mount(new MountedMapper("c", AnotherPage.class, new
>> CustomPageParametersEncoder("c")));
>>      }
>>      public Class getHomePage() {
>>           return IndexPage.class;
>>      }
>>
>> where CustomPageParametersEncoder creates the pageparameter from the url
>> in
>> method decodePageParameters().
>>
>> What doesn't work here, is that requests to /b are turned into requests to
>> /c, with pageparameter "c".
>>
>> So I end up, when requesting /b, with /c in my browser address bar, and
>> the
>> page saying "Hello, c", where I want to end up with /b in my address bar
>> and
>> the page saying "Hello, b".
>>
>> Your advice is very much appreciated,
>> kind regards
>> Heikki Doeleman
>>
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3989966.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
>>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Mounting page to mutliple urls with different pageparameter

Posted by Bas Gooren <ba...@iswd.nl>.
The latter problem is logical: your mapping is focused on incoming requests.
When wicket renders a link to AnotherPage.class, which url should be 
generated?

My guess is that a request for /b comes in, wicket then checks if the 
url is valid for AnotherPage.class by generating a url for it, which is 
/c (*).

*) See WebPageRenderer#respond(RequestCycle).

Simply put: you need to properly handle url generation, too :-)

Op 4-11-2011 13:53, schreef heikki:
> hello,
>
> I still find URL mapping to be far from easy. I can't get the following
> mapping to work; all advice very much appreciated:
>
> intented mapping is:
>
> /                      -->  map to IndexPage.class
> /b                    -->  map to AnotherPage.class with pageparameter
> param="b"
> /c                    -->  map to AnotherPage.class with pageparameter
> param="c"
>
> I tried creating a custom RootRequestMapper but I could not get it to work.
> The closest I've come to achieving the above url mapping is with this in my
> Application
>
>       protected void init() {
>            super.init();
>            mount(new MountedMapper("b", AnotherPage.class, new
> CustomPageParametersEncoder("b")));
>            mount(new MountedMapper("c", AnotherPage.class, new
> CustomPageParametersEncoder("c")));
>       }
>       public Class getHomePage() {
>            return IndexPage.class;
>       }
>
> where CustomPageParametersEncoder creates the pageparameter from the url in
> method decodePageParameters().
>
> What doesn't work here, is that requests to /b are turned into requests to
> /c, with pageparameter "c".
>
> So I end up, when requesting /b, with /c in my browser address bar, and the
> page saying "Hello, c", where I want to end up with /b in my address bar and
> the page saying "Hello, b".
>
> Your advice is very much appreciated,
> kind regards
> Heikki Doeleman
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3989966.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
>

Re: Mounting page to mutliple urls with different pageparameter

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

Custom root request mapper should be able to do it.
Just check the request's URL - if it has no segments then return the
home page, if it has one segment then return new
RenderPageRequestHandler(AnotherPage.class, new
PageParameters().add("param", segmentValue))

On Fri, Nov 4, 2011 at 2:53 PM, heikki <tr...@gmail.com> wrote:
> hello,
>
> I still find URL mapping to be far from easy. I can't get the following
> mapping to work; all advice very much appreciated:
>
> intented mapping is:
>
> /                      --> map to IndexPage.class
> /b                    --> map to AnotherPage.class with pageparameter
> param="b"
> /c                    --> map to AnotherPage.class with pageparameter
> param="c"
>
> I tried creating a custom RootRequestMapper but I could not get it to work.
> The closest I've come to achieving the above url mapping is with this in my
> Application
>
>     protected void init() {
>          super.init();
>          mount(new MountedMapper("b", AnotherPage.class, new
> CustomPageParametersEncoder("b")));
>          mount(new MountedMapper("c", AnotherPage.class, new
> CustomPageParametersEncoder("c")));
>     }
>     public Class getHomePage() {
>          return IndexPage.class;
>     }
>
> where CustomPageParametersEncoder creates the pageparameter from the url in
> method decodePageParameters().
>
> What doesn't work here, is that requests to /b are turned into requests to
> /c, with pageparameter "c".
>
> So I end up, when requesting /b, with /c in my browser address bar, and the
> page saying "Hello, c", where I want to end up with /b in my address bar and
> the page saying "Hello, b".
>
> Your advice is very much appreciated,
> kind regards
> Heikki Doeleman
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3989966.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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Mounting page to mutliple urls with different pageparameter

Posted by heikki <tr...@gmail.com>.
hello,

I still find URL mapping to be far from easy. I can't get the following
mapping to work; all advice very much appreciated:

intented mapping is:

/                      --> map to IndexPage.class
/b                    --> map to AnotherPage.class with pageparameter
param="b"
/c                    --> map to AnotherPage.class with pageparameter
param="c"

I tried creating a custom RootRequestMapper but I could not get it to work.
The closest I've come to achieving the above url mapping is with this in my
Application

     protected void init() {
          super.init();           
          mount(new MountedMapper("b", AnotherPage.class, new
CustomPageParametersEncoder("b")));
          mount(new MountedMapper("c", AnotherPage.class, new
CustomPageParametersEncoder("c")));
     }
     public Class getHomePage() {
          return IndexPage.class;
     }

where CustomPageParametersEncoder creates the pageparameter from the url in
method decodePageParameters(). 

What doesn't work here, is that requests to /b are turned into requests to
/c, with pageparameter "c". 

So I end up, when requesting /b, with /c in my browser address bar, and the
page saying "Hello, c", where I want to end up with /b in my address bar and
the page saying "Hello, b".

Your advice is very much appreciated,
kind regards
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3989966.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


Re: Mounting external pages to root

Posted by Martin Grigorov <mg...@apache.org>.
setup custom RootRequestMapper that delegates to the original and if
the original doesn't resolve any IRequestHandler then return
RenderPageRequestHandler(ExternalPage.class)

On Tue, Oct 11, 2011 at 5:00 PM, heikki <tr...@gmail.com> wrote:
> hi,
>
> forgive me for re-posting this, but it seems my code snippets in &lt;raw>
> tags are invisible in email ..
>
> I have a similar question, not sure if quite the same though. The pageflow
> is like this:
>
>
> (1) my app's homepage goes to a page with a loginform, SignInPage. On
> logging in the user gets to a page SignedInPage.
>
> (2) SignedInPage has a logout form, which logs out the user and should go
> back to SignInPage.
>
> (3) any other URL should be accepted and go to a page MainPage, which
> detects which URL path was used by checking PageParameters and could take
> action depending on its value.
>
>
> What is working fine are (1) and (3).  However on the SignedInPage, when
> submitting the logout form, an exception occurs indicating that it's trying
> to find the logout form on MainPage:
>
> Last cause: Could not find component 'logoutform' on page 'class
> my.package.page.MainPage
>
> Of course it isn't on MainPage, the logoutform is on SignedInPage.
>
> Can anyone tell me how to achieve a setup like this ? My current code is
> like this :
>
>
> In my Application init() I have
>
>      mountPage("/${username}", MainPage.class);
>      mountPage("/secure", SignedInPage.class);
>      mountPage("/", SignInPage.class);
>
> and I have also this method
>
>        public Class getHomePage() {
>             return SignInPage.class;
>        }
>
> The logoutform on SignedInPage has this in onSubmit() :
>
>      setResponsePage(SigninPage.class);
>
> Thanks in advance for your response,
> kind regards
> Heikki Doeleman
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3894513.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
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Mounting external pages to root

Posted by heikki <tr...@gmail.com>.
hi, 

forgive me for re-posting this, but it seems my code snippets in &lt;raw>
tags are invisible in email .. 

I have a similar question, not sure if quite the same though. The pageflow
is like this: 


(1) my app's homepage goes to a page with a loginform, SignInPage. On
logging in the user gets to a page SignedInPage. 

(2) SignedInPage has a logout form, which logs out the user and should go
back to SignInPage. 

(3) any other URL should be accepted and go to a page MainPage, which
detects which URL path was used by checking PageParameters and could take
action depending on its value. 


What is working fine are (1) and (3).  However on the SignedInPage, when
submitting the logout form, an exception occurs indicating that it's trying
to find the logout form on MainPage: 

Last cause: Could not find component 'logoutform' on page 'class
my.package.page.MainPage

Of course it isn't on MainPage, the logoutform is on SignedInPage. 

Can anyone tell me how to achieve a setup like this ? My current code is
like this : 


In my Application init() I have 

      mountPage("/${username}", MainPage.class);
      mountPage("/secure", SignedInPage.class);
      mountPage("/", SignInPage.class);

and I have also this method 

	public Class getHomePage() {
             return SignInPage.class;
	}

The logoutform on SignedInPage has this in onSubmit() : 

      setResponsePage(SigninPage.class);

Thanks in advance for your response, 
kind regards 
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3894513.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


Re: Mounting external pages to root

Posted by heikki <tr...@gmail.com>.
hi,

I have a similar question, not sure if quite the same though. The pageflow
is like this:


(1) my app's homepage goes to a page with a loginform, SignInPage. On
logging in the user gets to a page SignedInPage.

(2) SignedInPage has a logout form, which logs out the user and should go
back to SignInPage.

(3) any other URL should be accepted and go to a page MainPage, which
detects which URL path was used by checking PageParameters and could take
action depending on its value.


What is working fine are (1) and (3).  However on the SignedInPage, when
submitting the logout form, an exception occurs indicating that it's trying
to find the logout form on MainPage:



Of course it isn't on MainPage, the logoutform is on SignedInPage.

Can anyone tell me how to achieve a setup like this ? My current code is
like this :


In my Application init() I have

and I have this method


The logoutform on SignedInPage has this in onSubmit() :



Thanks in advance for your response,
kind regards
Heikki Doeleman

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Mounting-external-pages-to-root-tp3890756p3894477.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