0

Fetching Key-Value pair for ComboBox using SimpleListModel

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

hrv gravatar image hrv
35 3

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

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
1

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

MDuchemin gravatar image MDuchemin
1246 1 3
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
0

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

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

Follow
1 follower

RSS

Stats

Asked: 2017-05-01 12:49:01 +0000

Seen: 32 times

Last updated: May 08

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