-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi All,
I am filling up my Combobox using setModel method, now my problem is how can I set selected the value. I am using call back listener "onInitRenderLater" but when I try to call setSelectedIndex it gives me following error.
org.zkoss.zk.ui.UiException: Out of bound: 20 while size=0
And rightly so, because as I understand this, it loads the content when I start typing.
Even the box.getItemCount() returns 0, Only when I start typing that gets updated, that too it shows only selected items' count. (If I have written just a, it gives me the count of items starting with a only)
Please help me here to set selected item.!
Hey,
I altered your fiddle so it should work :
Answer based on ZK version 3.6:
since the model doesn't keep any selection in 3.6 and the comboitems are created/destroyed on demand the simplest thing would be to use combo.setValue("bombard") to set the initial value.
Or just create your own comboitem containing the initial value. However this will be destroyed when another comboitem is selected.
combo.setValue("bombard");
or
Comboitem initialSelectedItem = new Comboitem("bombard");
combo.appendChild(initialSelectedItem);
combo.setSelectedItem(initialSelectedItem);
Does this make any sense for your scenario?
In the end a combobox is merely a String input field with automatic suggestions based on a model. The comboitems themselves come and go when generated driven by a ListModel.
Robert
Asked: 2017-05-03 12:11:30 +0800
Seen: 95 times
Last updated: May 19 '17
How to capture onScroll Event of Combobox
combobox does not scroll autocompleted text into view
I want to take different value from label(value) and pass to @bind object
Combobox sometimes clears the selected item
zk combobox filtering option is not working inside listbox .
Zk create custom event for COmbo box?
Fetching Key-Value pair for ComboBox using SimpleListModel
ComboBox autocomplete does not work with onOk event [closed]
your model contains the selected item.
chillworld ( 2017-05-03 12:44:49 +0800 )editMy model contains all the items, but how to set the selected one back in the combobox when I am reloading the page?
hrv ( 2017-05-03 13:02:50 +0800 )editare you using mvvm, mvc? if possible just create a zk fiddle with your code
chillworld ( 2017-05-03 15:28:17 +0800 )editHi, thanks for the answer..! I am using the same demo example of ZK for now https://www.zkoss.org/zksandbox/#f5 Just the change is I am doing it from my Java files..
Here is the fiddle http://zkfiddle.org/sample/3ifu29k/5-Another-new-ZK-fiddle#source-2
hrv ( 2017-05-05 04:44:35 +0800 )editOh, yes.. It's perfect, but my issue is my ZK version is a bit older (3.6) which does not have "addToSelection" method. :(
I should have mentioned it earlier, I am sorry..!
hrv ( 2017-05-05 06:48:58 +0800 )edit