Make request parameters available in page constructors.

3 messages Options
Embed this post
Permalink
Finn Bock

Make request parameters available in page constructors.

Reply Threaded More More options
Print post
Permalink
Hi,

Is there a reason that the constructor in Page does not call
processPageRequestParams(this) in ClickServlet? If it did, request
parameters would be assigned to the @Bindable/public fields in Page
subclasses and would be available for the constructors in page
subclasses.

The drawback is that initial values for @Bindable fields will override
the request parameters:

public class MyPage extends Page {
    @Bindable public String param1;
    @Bindable public String param2 = "default";

    public class MyPage() {
        // here param1 will have the value from the request, but
param2 will always be "default".
    }
}

If the current call to processPageRequestParams() in
ClickServlet.initPage() is kept, the correct value will be set and
available for onInit(), so it could be made backward compatible.

Or perhaps the processPageRequestParams() method could be made
available for explicit call:

    public class MyPage() {
        getContext().processPageRequestParams(this)
        // here both param1 and param2 will have values from the request.
    }

regards,
Finn
Tim Hooper-2

Re: Make request parameters available in page constructors.

Reply Threaded More More options
Print post
Permalink
There's been many times i've wished Click had this feature!

Bob Schellink-2

Re: Make request parameters available in page constructors.

Reply Threaded More More options
Print post
Permalink
In reply to this post by Finn Bock
Hi Finn,

We should probably keep the existing functionality as is, but as you
suggested, expose context.processPageRequestParams to allow users to
explicitly bind request params in a BorderPage constructor.

kind regards

bob

Finn Bock wrote:

> Hi,
>
> Is there a reason that the constructor in Page does not call
> processPageRequestParams(this) in ClickServlet? If it did, request
> parameters would be assigned to the @Bindable/public fields in Page
> subclasses and would be available for the constructors in page
> subclasses.
>
> The drawback is that initial values for @Bindable fields will override
> the request parameters:
>
> public class MyPage extends Page {
>     @Bindable public String param1;
>     @Bindable public String param2 = "default";
>
>     public class MyPage() {
>         // here param1 will have the value from the request, but
> param2 will always be "default".
>     }
> }
>
> If the current call to processPageRequestParams() in
> ClickServlet.initPage() is kept, the correct value will be set and
> available for onInit(), so it could be made backward compatible.
>
> Or perhaps the processPageRequestParams() method could be made
> available for explicit call:
>
>     public class MyPage() {
>         getContext().processPageRequestParams(this)
>         // here both param1 and param2 will have values from the request.
>     }
>
> regards,
> Finn
>