Just for clarification, does the JavaScript function that captures the Select
value do a normal Form
submit or an Ajax request?
Also what is the name of the Select field?
Essentially it sounds as if the form post does not pass a parameter called
"myParameter". You can
confirm this by looking at the "Net" tab in Firefox's FireBug plugin.
Kind regards
Bob
On 30/04/2010 10:05, Dipita Shah wrote:
> I'm sending this here since my mails to the forum seem to be bouncing..
>
> Thanks Bob. I do actually use the request parameter from the context
> like this:
>
> public class myPage extends Page {
> Panel myPanel;
> String myParameter;
>
> public onInit() {
> myParameter= getContext().getRequestParameter("myParameter");
> myPanel = new abcPanel(myParameter); //this is passed to the
> constructor to figure what pararm. to use
> myPanel.initializeFields();
> add(myPanel);
> } ...
> }
>
> BTW, I don't have access to the Select control - it is created in the
> form creation (in the Panel class).
>
> When the user changes the selection, a javascript function captures the
> new value and passes it as a request parameter to reload the page with
> the new parameter (which recreates the form based on this parameter.)
>
> This all works when just changing selections. But as soon as the submit
> button is invoke, the request parameter on the onInit() (which seems to
> happen before the listener is invoked) of the page is null --> I am not
> understanding why this is null? Any ideas?
>
> Thanks!
> Dipita
>
> -----Original Message-----
> From: Bob Schellink [mailto:[email protected]]
> Sent: Thursday, April 29, 2010 4:05 PM
> Cc: Dipita Shah
> Subject: Re: Question about onInit() and listener invokation - where to
> initialize
>
> Hi Dipita,
>
> You are correct in that the Select field will need to be bound to its
> request value *before* the
> Form is initialized. The normal life cycle of Click is to bind request
> values during the onProcess
> event, which is *after* the Form was initialized. One way to retrieve
> the Select request value is
> from the Context object.
>
>
> public void onInit() {
> getContext().getRequestParameter("mySelect"); // <- mySelect will be
> the Select field name
> }
>
>
> or if you have access to the Select, do this:
>
> public void onInit() {
> Select select = new Select("mySelect");
> select.add("option 1");
> select.add("option 2");
> ...
>
> select.bindRequestValue(); // <- will bind the select to its
> incoming value
> String parameter = select.getValue();
> }
>
>
> In your example I'm unsure if the Select is created inside the
> addFieldsBasedonParameter or before.
> I assume it is created before. So you can modify it as follows:
>
> public initailizeFields() {
> select = new Select("myselect");
> select.add("option 1");
> ...
> select.bindRequestValue();
> String parameter = select.getValue();
>
> myForm = new Form("myForm");
> addFieldsBasedonParameter(parameter);
> }
>
>
> In the upcoming 2.2.0 we have added helper methods to bind and validate
> fields and forms to cater
> for this exact scenario you describe above.
>
> Does that help?
>
> Kind regards
>
> Bob
>
> On 30/04/2010 04:03, dshah [via click] wrote:
>> Hi,
>> I have read all the forum questions on this topic and am unsure the
>> correct way of implementing what I want to do:
>>
>> I have a page that contains a panel. In the onInit() method of the
>> page, I create the panel and initialize a Form in that Panel.. as
> follows:
>>
>> public class myPage extends Page {
>> Panel myPanel;
>>
>> public onInit() {
>> myPanel = new abcPanel(...);
>> myPanel.initializeFields();
>> add(myPanel);
>> }
>> ...
>> }
>>
>> public class myPanel extends Panel {
>> Form myForm;
>>
>> public myPanel(..) {
>> //do some construction work
>> }
>> public initailizeFields() {
>> myForm = new Form("myForm");
>> addFieldsBasedonParameter(parameter) // this will populate the
>> various fields for the form based on the parameter. The default
>> parameter only has a small subset of the fields..
>> }
>> }
>>
>> Now my problem is that my default parameter (which is used to figure
> out
>> which fields should be created on the form) only have a subset of
>> fields. Depending on this parameter, the fields could be more or
> less..
>> This parameter is a Select Control which is added to the form. The
> user
>> can select this parameter (and if the selection is changed, I reload
> the
>> page with the parameter) As I said some of these parameters will load
>> more fields..
>>
>> Now my problem is that before the onSave (aka listener method of the
>> form click event) is called, the onInit() is called - which recreates
>> the Form with the default paramter (although this parameter was
> changed
>> when the user changed the selection...) So by the time the onSave
>> listener is invoked, some fields that should be on the Form are not
>> there (because the form was recreated with default parameters in the
>> onInit() method..)
>>
>> What is the best way to handle this - the form fields have to be
>> generated dynamically based on the user's selection..
>>
>> Any help is appreciated.
>> Thanks!
>> Dipita
>>
>>
> ------------------------------------------------------------------------
>> This email was sent by dshah
>>
> <http://click.1134972.n2.nabble.com/user/UserRootNodes.jtp?user=373530>
>> (via Nabble)
>> Your replies will appear at
>>
> http://click.1134972.n2.nabble.com/Question-about-onInit-and-listener-in
> vokation-where-to-initialize-tp4981417p4981417.html
>> To receive all replies by email, subscribe to this discussion
>>
> <http://click.1134972.n2.nabble.com/subscriptions/Subscribe.jtp?code=c2F
> ib2IxQGdtYWlsLmNvbXw0OTgxNDE3fC00OTUyOTIwOTU=>
>>
>
>