Chosenbox save selected value to db and display selection into chosenbox

asked 2021-05-16 03:29:26 +0800

AmolAnturkar gravatar image AmolAnturkar

Dear Support,

I m using chosenbox to save selectedobjects to database and I want to retrieve those db values into chosenbox as selected value. Can you please help how I can achieve this? Thanks!

With Best Regards, Amol

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2021-05-17 15:07:38 +0800

cor3000 gravatar image cor3000
5920 2 7
ZK Team

I assume you already know how to save/load data into your DB (since persistence layers are not part of ZK I'll not cover those details here)

If you're using Chosenbox I assume you use a ListModelList (or another ListModel implementation supporting Selectable) for the available items. By doing so this ListModelList can serve both your requirements.


ListModelList<String> namesModel = 
    new ListModelList<>(Arrays.asList("Adam", "Eve", "Harold", "Spencer"));


Now the user can pick from the available names in the model, the namesModel will keep track of the current selected names.

In order to retrieve the current selection (saving into DB) you call:

Set<String> selectedNames = namesModel.getSelection();

When loading a previous selection you simply add the loaded names to the selection of the names Model.

Collection<String> selectedNames = yourService.loadSelectedNames();

or add/remove them one by one:


Does this help? If you needed something different please consider providing some runnable code on https://zkfiddle.org/ and post the link here.

link publish delete flag offensive edit

answered 2021-05-17 20:48:24 +0800

AmolAnturkar gravatar image AmolAnturkar

Many Thanks for your help and advise! Yes its helpful and Since, I am new to ZK Please let me digest this and update. Further more info, I am using MVVM pattern and used "selectedobjects" with command @save to pass it to VM and then db. Now I am trying to load those db value into chosenbox as selectedobjects.

With Best Regards, Amol

link publish delete flag offensive edit


you're welcome

cor3000 ( 2021-05-18 09:16:31 +0800 )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: 2021-05-16 03:29:26 +0800

Seen: 12 times

Last updated: May 17

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