0

Combox setSelectIndex

asked 2009-10-29 09:58:45 +0800

obiwan gravatar image obiwan
57 2
http://www.payroll.it

Hi,
i'm working on a simple form that need to be initializated at startup.
If i use the code:

<window id="win" apply="MyController">
  <combobox id="years"/>
</window>

public class MyController extends GenericAutowireComposer {
  private Combobox years;

  public onCreate$win() {
    
    years.setModel(new ListModelList(Arrays.asList("2007", "2008", "2009")));
    years.setSelectedIndex(2);
  }
}

when the window appear i recieve an IndexOutOfBound Exception like the combobox was not ready.

But if instead i use Listbox in place of Combobox:

<window id="win" apply="MyController">
  <listbox id="years" mold="select" rows="1"/>
</window>

public class MyController extends GenericAutowireComposer {
  private Listbox years;

  public onCreate$win() {
    
    years.setModel(new ListModelList(Arrays.asList("2007", "2008", "2009")));
    years.setSelectedIndex(2);
  }
}

all works fine ....
Now my question is, there is any lack in the combobox implementation or i'm missing anything ?

Thank,

delete flag offensive retag edit

7 Replies

Sort by ยป oldest newest

answered 2009-10-29 16:26:52 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-10-29 16:27:47 +0800

Hi Obiwan,

only a hint. You can let the listbox looking as a normal known combobox with the rows="1" attribute.

   <listbox id="kunBranche" width="100%" mold="select" rows="1" />

link publish delete flag offensive edit

answered 2009-10-29 17:31:44 +0800

obiwan gravatar image obiwan
57 2
http://www.payroll.it

updated 2009-10-29 17:32:45 +0800

Yes Terry, i'm using the listbox in this way at the moment but i wanted to point out this anomaly to the staff.
I think that combobox is a more fashionable component then listbox.

link publish delete flag offensive edit

answered 2009-10-30 06:22:52 +0800

obiwan gravatar image obiwan
57 2
http://www.payroll.it

Thanks to jumperchen i resolved the problem.
On this scenario we can add an event listener to the combobox to listen at the onInitRenderLater event that is called after combobox renderig phase (obvious).
Now the code works fine.

<window id="win" apply="MyController">
  <combobox id="years"/>
</window>

public class MyController extends GenericAutowireComposer {
  private Combobox years;

  public onCreate$win() {
    years.addEventListener("onInitRenderLater", this);
    years.setModel(new ListModelList(Arrays.asList("2007", "2008", "2009")));    
  }

  public void onEvent(Event e) {
    years.setSelectedIndex(2);
  }
}

Thanks

link publish delete flag offensive edit

answered 2009-10-30 16:40:16 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Many thanks obiwan,

your post is a good example for a perfect Q&A.
The needed zul-lines and the corresponding java code solution.

thanks
Stephan

link publish delete flag offensive edit

answered 2009-11-19 15:42:00 +0800

n4rk0 gravatar image n4rk0
120 3

I was having the same problem. But I used the event listener in the onAfterCompose instead of onCreate event, and it works fine too. I noticed that if I have an autowire function like :


public void onChange$cmbTipoDocumento(Event event){
    ...
}


This won't execute never and the onEvent will execute allways. So I declared a bool attribute that controls the first time that I enter in the onEvent event, because I only want that setSelectedIndex executes once. This is the code :


public class EmisionContratanteController extends GenericForwardComposer{

    ...
    private boolean boolEvento = false;
    ...

    public void onEvent(Event e){
    if(!boolEvento){
        cmbTipoDocumento.setSelectedIndex(intTipoDocumentoIndex);
        boolEvento = true;
    }else{
        ... // Here is the code of the autowire function onChange$cmbTipoDocumento
    }
}


With this, the function onChange$cmbTipoDocumento is not needed anymore.
Hope it will be useful
Regards

link publish delete flag offensive edit

answered 2009-11-26 05:52:05 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

Just to update obiwan's code with a newer version:

<window id="win" apply="MyController">
  <combobox id="years"/>
</window>

public class MyController extends GenericAutowireComposer {
  private Combobox years;

  public onCreate$win() {
    years.setModel(new ListModelList(Arrays.asList("2007", "2008", "2009")));    
  }

  public void onInitRenderLater$years(Event e) {
    years.setSelectedIndex(2);
  }
}

Now we don't need to override onEvent method.

Cheers,

link publish delete flag offensive edit

answered 2009-11-26 13:44:33 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Great ! Thanks Felipe.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-10-29 09:58:45 +0800

Seen: 1,795 times

Last updated: Nov 26 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More