-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi... Sorry for many questions, but I've one more:
In ZUL I have this code:
<listbox id="list" model="@{model.values}" selectedItem="@{model.selectedValue}"
But I need do the same in Java... How databinding works in Java? I would like to have my bean set with the selected item model value... I also would like to select the item in Java... I have an "item" from "model.values", and would like to do this as the first selected item
My Java Code:
final Listbox valuebox = new Listbox(); valuebox.setModel(valueModelList); valuebox.setItemRenderer(valueListItemRenderer); valuebox.setMold("select"); valuebox.setRows(1); valuebox.setMultiple(false); // Select an item - valuebox.select(mybean.getValue() ) HOW???? valuebox.addEventListener("onSelect", new EventListener(){ public void onEvent(Event arg0) throws Exception { Listitem item = valuebox.getSelectedItem(); mybean.setValue( (Value) item.getValue()); }
Is this the way? Have I to implement a EventListener, to set the property in my bean? In my renderer I set Lisitem value with the "value" object...
The listbox has the selectItem(Listitem item) method... I don't have the Listitem object, but I've a Value object, that is in the model... So, how can I select this item, when I have a model and the the model contains the object I wish select ? In ZUL I have selectedItem="@{model.selectedValue}", but in Java?
I read some posts about this situation, but it's clear for me....
Thanks!
I think you can use
valuebox.setSelectedIndex(INT_INDEX_FOR_ITEM or a ListItem object);
Or you can set the attribute on one of the children ListItems;
listitem.setSelected(true);
Iterate over valuebox.getItems() and look for the id (not index) and set the selected item etc.
Dunno maybe there is a much more easy way also..?
OK..
I think should have a method like:
valuebox.setSelectedItemFromModel(Object object);
So, Zk should search in the ListModel for the object and set the right ListItem as selected;
<listbox id="list" model="@{model.values}" selectedItem="@{model.selectedValue}"
In ZUL it is done... I've a model, and the selectedItem is binded to a bean.. So, when I change the model.selectedValue ZK set the right selected Listitem...
In Java I have to:
- Iterate over valuebox.getItems()
- Compare Listitem value with my bean
- Set Listitem.selected property
I think doing this work in ZUL is better, but in some cases it's not possible (Tabbox generated on-the-fly). So I have to do it in Java... I thunk ZK should provide the same king of options in ZUL also in Java... (annotation dataBinder, item selection: model="@{model.values}" selectedItem="@{model.selectedValue}"). If is possible do it in Java too easy as in ZUL, please help me, because I've found some problems with it.
[]s
Well the whole system is written i java, so i guess it should be possible to use the same classes/interfaces as the zul files. Have not digned deep enougth into the source code there yet. I think there is some small talkes about the things behind the sceen there also..
Asked: 2009-01-13 02:18:38 +0800
Seen: 1,119 times
Last updated: Jan 15 '09