How to set selected combobox when using setModel

asked 2017-05-03 12:11:30 +0800

hrv gravatar image hrv
35 3

updated 2017-05-03 12:22:33 +0800

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.!

delete flag offensive retag edit


your model contains the selected item.

chillworld ( 2017-05-03 12:44:49 +0800 )edit

My 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 )edit

are you using mvvm, mvc? if possible just create a zk fiddle with your code

chillworld ( 2017-05-03 15:28:17 +0800 )edit

Hi, 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 )edit

Oh, 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

3 Answers

Sort by ยป oldest newest most voted

answered 2017-05-04 01:20:45 +0800

hawk gravatar image hawk
3185 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2017-05-04 10:20:19 +0800

cor3000 gravatar image cor3000
6280 2 7

please call model.addToSelection(E)

link publish delete flag offensive edit


Actually I am using older version of ZK (3.6) (In Adempiere ERP) which does not have "addToSelection" method, can you please suggest any other way out?

hrv ( 2017-05-08 06:23:47 +0800 )edit

that would have been a critical information upfront... in the VERY old version 3.6 a ListModel doesn't contain the selection yet and obviously not the related methods, so please ignore any previous suggestions for your case.

cor3000 ( 2017-05-19 06:06:33 +0800 )edit

answered 2017-05-05 06:34:50 +0800

chillworld gravatar image chillworld flag of Belgium
5357 4 9


I altered your fiddle so it should work :


link publish delete flag offensive edit


removed the correct answer flag... since the questions conditions changed to ZK 3.6

cor3000 ( 2017-05-19 07:03:47 +0800 )edit

answered 2017-05-19 06:59:12 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2017-05-19 07:02:03 +0800

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.



Comboitem initialSelectedItem = new Comboitem("bombard");

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.


link publish delete flag offensive edit
Your answer
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

1 follower



Asked: 2017-05-03 12:11:30 +0800

Seen: 95 times

Last updated: May 19 '17

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