You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Sebastien <se...@gmail.com> on 2015/11/18 15:49:54 UTC

PageParameters & mounted pages

Hi,

I have a little concerns about PageParameters and mounted pages.

On a first case - mypage?param=myvalue - I can retrieve param from both
page-parameters and from Request#getQueryParameters()

On a second case - mypage/myvalue (with a mounted page /mypage/${param}) -
I am able to retrieve param only from page-parameters, but not from the
request cycle (Request#getQueryParameters())

Is it intended?

I saw a previous thread on a similar topic, which suggests to parse
requestCycle.getRequest().getUrl() but it looks a little bit weird to me
and I was wondering if there is no other (built-in) feature...

My context is the following: I am trying to secure a mounted page like this
(this is currently just a POC...)

@OACCAuthorizeInstantiation(resource = "${myparam}", permission = "VIEW")

In OACCAuthorizationStrategy#isInstantiationAuthorized(Class<T>
componentClass), I have access to the component class type, not the
component/page instance so I cannot call #getPageParameters anyhow...


Many thanks in advance,
Sebastien

Re: PageParameters & mounted pages

Posted by Sebastien <se...@gmail.com>.
Hi Martin,

Thank you very much for this explanation and suggestion!

As you said, both are GET parameters (and actually, both are accessible
thought page-parameters), so from a user point of view it is strange that
one is not considered as a "request parameter".

Consider a user, who used to get the parameter via the request-cycle. Later
on, he decides to mount this parameter because the url becomes much
nicer... I can hear from here: "Oops ! It does not work anymore, that's
strange!" (trust me, I know what I talking about :p)

So to answer your question if it should be the default or not: from my
point of view it would be yes. But I do not have the whole picture on this
mapper topic and don't know what could be the drawback(s)... What does
other devs think about this? Does it make sense to be the default?

I will try your suggestion anyway, thanks again! :)

Best regards,
Sebastien.


On Wed, Nov 18, 2015 at 4:28 PM, Martin Grigorov <mg...@apache.org>
wrote:

> Hi Sebastien,
>
> The problem is that Request#getQueryParameters() is about - parameters in
> the query string.
> And "/mypage/${param}" uses parameter in the path.
> Both of these are GET parameters but they are different.
>
> To get the correct values you should use something like:
>
> IRequestHandler handler = application.getRootRequestMapper().map(request);
> if (handler instance of IPageClassRequestHandler) {
>   // cast and
> use
> org.apache.wicket.core.request.handler.IPageClassRequestHandler#getPageParameters
> }
>
> You see this is much more time consuming operation than parsing the query
> string parameters from a String (the url).
> Maybe this should be the default, maybe not. I am not sure.
>
> You can also make use
> of
> org.apache.wicket.request.cycle.PageRequestHandlerTracker#getFirstHandler()
> to skip the resolution of the IRequestMapper.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
> On Wed, Nov 18, 2015 at 3:49 PM, Sebastien <se...@gmail.com> wrote:
>
> > Hi,
> >
> > I have a little concerns about PageParameters and mounted pages.
> >
> > On a first case - mypage?param=myvalue - I can retrieve param from both
> > page-parameters and from Request#getQueryParameters()
> >
> > On a second case - mypage/myvalue (with a mounted page /mypage/${param})
> -
> > I am able to retrieve param only from page-parameters, but not from the
> > request cycle (Request#getQueryParameters())
> >
> > Is it intended?
> >
> > I saw a previous thread on a similar topic, which suggests to parse
> > requestCycle.getRequest().getUrl() but it looks a little bit weird to me
> > and I was wondering if there is no other (built-in) feature...
> >
> > My context is the following: I am trying to secure a mounted page like
> this
> > (this is currently just a POC...)
> >
> > @OACCAuthorizeInstantiation(resource = "${myparam}", permission = "VIEW")
> >
> > In OACCAuthorizationStrategy#isInstantiationAuthorized(Class<T>
> > componentClass), I have access to the component class type, not the
> > component/page instance so I cannot call #getPageParameters anyhow...
> >
> >
> > Many thanks in advance,
> > Sebastien
> >
>

Re: PageParameters & mounted pages

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

The problem is that Request#getQueryParameters() is about - parameters in
the query string.
And "/mypage/${param}" uses parameter in the path.
Both of these are GET parameters but they are different.

To get the correct values you should use something like:

IRequestHandler handler = application.getRootRequestMapper().map(request);
if (handler instance of IPageClassRequestHandler) {
  // cast and
use org.apache.wicket.core.request.handler.IPageClassRequestHandler#getPageParameters
}

You see this is much more time consuming operation than parsing the query
string parameters from a String (the url).
Maybe this should be the default, maybe not. I am not sure.

You can also make use
of org.apache.wicket.request.cycle.PageRequestHandlerTracker#getFirstHandler()
to skip the resolution of the IRequestMapper.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Wed, Nov 18, 2015 at 3:49 PM, Sebastien <se...@gmail.com> wrote:

> Hi,
>
> I have a little concerns about PageParameters and mounted pages.
>
> On a first case - mypage?param=myvalue - I can retrieve param from both
> page-parameters and from Request#getQueryParameters()
>
> On a second case - mypage/myvalue (with a mounted page /mypage/${param}) -
> I am able to retrieve param only from page-parameters, but not from the
> request cycle (Request#getQueryParameters())
>
> Is it intended?
>
> I saw a previous thread on a similar topic, which suggests to parse
> requestCycle.getRequest().getUrl() but it looks a little bit weird to me
> and I was wondering if there is no other (built-in) feature...
>
> My context is the following: I am trying to secure a mounted page like this
> (this is currently just a POC...)
>
> @OACCAuthorizeInstantiation(resource = "${myparam}", permission = "VIEW")
>
> In OACCAuthorizationStrategy#isInstantiationAuthorized(Class<T>
> componentClass), I have access to the component class type, not the
> component/page instance so I cannot call #getPageParameters anyhow...
>
>
> Many thanks in advance,
> Sebastien
>