Fetching Key-Value pair for ComboBox using SimpleListModel

asked 2017-05-01 12:49:01 +0800

hrv gravatar image hrv
35 3

updated 2017-05-05 12:23:43 +0800

Hi All,

I want my Combobox to be Autosuggest box, where I am fetching all products. Now to make Combobox autosuggest I a understand the only option is to load it using setModel function.

But the problem I am facing here is if I set String array like below, I can't get the product id of it.

(ListModel lml=new SimpleListModel(Dictionary.getDirectory()))

I have taken reference from w3.zkoss.org/zkdemo/combobox/autocomplete

Please help me solve the issue.

Here is the fiddle that has the example, currently I am setting all values in combobox, which I want to be Key-Value pairs. zkfiddle.org/sample/3ifu29k/6-Another-new-ZK-fiddle

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2017-05-05 14:29:19 +0800

MDuchemin gravatar image MDuchemin
2375 1 6
ZK Team

Hi Hrv,

Before talking about the combobox itself, I would highly recommend reading about the MVC / MVVM patterns in the ZK documentation. Implementing UI logic directly in an extended component might seem OK at first, but it will turn in a nightmare to extend / maintain very quickly.

Using SimpleListModel is possible, but keep in mind that it is immutable once created. For many purposes, you may want to look at more convenient ListModel implementations such as ListModelList, ListModelArray, ListModelMap I also recommend reading the combobox autocomplete section of the documentation here

This said, here is an example of how you could do what you described: http://zkfiddle.org/sample/6gn1kh/1-Autocomplete-in-combobox-with-beans

PS: you can should be able to add links to your posts now ;)

link publish delete flag offensive edit

answered 2017-05-08 06:18:48 +0800

hrv gravatar image hrv
35 3

Hi Sir, I did something similar, used an overridden ComboItem (instead of MyEntityBean) So that I am getting all the components. But thanks for the help.

But one thing here is I need to set the selected value to the ComboBox, I know model.addToSelection(E) but here I am using older version of ZK (~3.6.3).

Can you help me set the value back in this older version please?

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-01 12:49:01 +0800

Seen: 47 times

Last updated: May 08 '17

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