click-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Schellink <>
Subject Re: Question about onInit() and listener invokation - where to initialize
Date Thu, 29 Apr 2010 23:03:59 GMT
Hi Dipita,

You are correct in that the Select field will need to be bound to its request value *before*
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
from the Context object.

  public void onInit() {
    getContext().getRequestParameter("mySelect"); // <- mySelect will be the Select field

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
I assume it is created before. So you can modify it as follows:

  public initailizeFields() {
    select = new Select("myselect");
    select.add("option 1");
    String parameter = select.getValue();

    myForm = new Form("myForm");

In the upcoming 2.2.0 we have added helper methods to bind and validate fields and forms to
for this exact scenario you describe above.

Does that help?

Kind regards


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
> <>
> (via Nabble)
> Your replies will appear at
> To receive all replies by email, subscribe to this discussion
> <>

View raw message