0

How to set selected combobox when using setModel

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

hrv gravatar image hrv
35 3

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

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

Comments

your model contains the selected item.

chillworld ( 2017-05-03 12:44:49 +0000 )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 +0000 )edit
1

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

chillworld ( 2017-05-03 15:28:17 +0000 )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 +0000 )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 +0000 )edit

3 Answers

Sort by ยป oldest newest most voted
1

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

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

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

cor3000 gravatar image cor3000
3260 1 6
ZK Team

please call model.addToSelection(E)

link publish delete flag offensive edit

Comments

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 +0000 )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 +0000 )edit
0

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

chillworld gravatar image chillworld flag of Belgium
5128 3 9
https://github.com/chillw...

Hey,

I altered your fiddle so it should work :

http://zkfiddle.org/sample/3ifu29k/6-Another-new-ZK-fiddle

link publish delete flag offensive edit

Comments

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

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

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

cor3000 gravatar image cor3000
3260 1 6
ZK Team

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

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

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

Follow
1 follower

RSS

Stats

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

Seen: 45 times

Last updated: May 19

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