Revision history [back]

click to hide/show revision 1
initial version

answered 2021-03-09 10:49:59 +0800

cor3000 gravatar image cor3000

ZK Team

EDIT: The problem seems to be related to ListModelList, if i use ArrayList this doesn't happen.

Seems you already found the cause. That's exactly the correct/expected behavior, since the ListModelList implements the Selectable interface it will keep track of the current selected item, if the same listModel instance is applied to multiple comboboxes they will all synchronize on the current selection.

So one way you already found is to use ArrayList which does not implement Selectable so the selection is not synchronized. (ZK will wrap this Arraylist into a new ListModelList for each combobox keeping the selection separate)

No need to worry this is all working fully 'normal'. Using ArrayList is a valid decision if the same items should be reused between multiple comboboxes but the selection needs to be kept separate.

I took the freedom to update your example and remove a few unnecessary things (E.g. a list of Strings doesn't need a comboitem template this will just automatically do the same by default, the value is the item in the collection (a string), the label is the item.toString() - the same string). https://zkfiddle.org/sample/2msj324/5-Multiple-combobox-reduced

EDIT: The problem seems to be related to ListModelList, if i use ArrayList this doesn't happen.

Seems you already found the cause. That's exactly the correct/expected behavior, since the ListModelList implements the Selectable interface it will keep track of the current selected item, if the same listModel instance is applied to multiple comboboxes they will all synchronize on the current selection.

So one way you already found is to use ArrayList which does not implement Selectable so the selection is not synchronized. (ZK will wrap this Arraylist into a new ListModelList for each combobox keeping the selection separate)

No need to worry this is all working fully 'normal'. Using ArrayList is a valid decision if the same items should be reused between multiple comboboxes but the selection needs to be kept separate.

I took the freedom to update your example and remove a few unnecessary things (E.g. a list of Strings doesn't need a comboitem template this template. ZK will just automatically do the same by default, the value is the item in value will be the each object from the collection (a (here a string), the label is the item.toString() will be computed via each.toString() - the same string). https://zkfiddle.org/sample/2msj324/5-Multiple-combobox-reduced

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