Combobox SelectedItem value

asked 2021-04-19 15:28:10 +0800

aUser gravatar image aUser
123 4


I have created this fiddle as i was trying to do this:

I have a model of custom objects and i connect this model to a combobox. When a user selects an item, i would like to bind a field of that selected custom object to an attribute of my view model. As you can see in the fiddle, i would like to store in a String only the Id of the Decode Object. However when i select an item and display the value of the selected item, i get the toString() value of the Decode Object.

Is it possible to do something like this or do i necessarily need to bind the selectedItem to a Decode object in my viewModel?

Thank you

delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted

answered 2021-04-20 17:23:53 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

you can use children-binding or the <forEach> shadow element if you need a dynamic list of choices

link publish delete flag offensive edit


From https://www.zkoss.org/wiki/SmallTalks/2017/March/ZK8FeaturesforMVC-ShadowElements-Part2 paragraph "Static usage" i assume that the <forEach> component cannot help me in this case since i need to know the selected item. I'll just stick to the children binding then..

aUser ( 2021-04-21 00:02:26 +0800 )edit

https://zkfiddle.org/sample/l1anaj/12-children-multiple-combo can you please check this fiddle? the second combobox depends on the first one. When i change an item in the first combobox, i need to clear the selected item in the second combobox, i cannot find a way to do this with children binding..

aUser ( 2021-04-21 05:57:58 +0800 )edit

answered 2021-04-20 11:58:48 +0800

cor3000 gravatar image cor3000
5868 2 7
ZK Team

When using a ListModelList then the ListModel is taking handling the selection based on the objects in the ListModel. In the presence of a ListModel the binding at selectedItem will use a converter to retrieve the selected object from the model and neither the <comboitem> nor the comboitem value.


Instead without a model you can use the comboitem.value as the selectedItem.


Here your updated fiddle (using an ArrayList instead of a ListModelList): https://zkfiddle.org/sample/1f8jmg1/2-Combobox-SelectedItem

An alternative would be to implement your own converter.

link publish delete flag offensive edit

answered 2021-04-20 15:28:20 +0800

aUser gravatar image aUser
123 4

Ok, but using the EL expression when loading the items i cannot change the collection, right? (like adding or removing items at runtime)

The only way for that to work is to implement a converter, is that correct?

link publish delete flag offensive edit

answered 2021-04-20 18:31:39 +0800

aUser gravatar image aUser
123 4

updated 2021-04-20 23:15:14 +0800

I tried children-binding, not sure if this is how you would do it. Doesn't work correctly when i select an item..

About <forEach> i don't understand how to use it with a combobox, grid or listbox. Say for example i want to use combobox to know the selected item, how can i make it work with the forEach component?

Update: My bad, in the fiddle i forgot to replace each with item.. Works fine with the children option.. Thank you cor3000

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: 2021-04-19 15:28:10 +0800

Seen: 12 times

Last updated: Apr 20

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