-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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,
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" />
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.
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
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
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){ ... }
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 } }
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,
Great ! Thanks Felipe.
Asked: 2009-10-29 09:58:45 +0800
Seen: 1,795 times
Last updated: Nov 26 '09