Listbox multiple data binding (getSelectedItems/setSelectedItems)

asked 2010-02-24 08:24:13 +0800

stephenb gravatar image stephenb
54 1

With ZK 3.6.2, I have a Listbox that displays Strings:

<listbox multiple="true" selectedItems="@{manager.selectedItems}">
  <listitem value="a" label="A" />
  <listitem value="b" label="B" />

and in the manager class:

private Set selectedItems = new HashSet();
public Set getSelectedItems() {
  return selectedItems();
public void setSelectedItems( Set selectedItems ) {
  this.selectedItems = selectedItems;

I expected my setSelectedItems(Set) method to be called when I selected items in the listbox, but it was not.

Is there a simple way to bind a multiple selections listbox to a Set when the values are Strings? If not, what is the correct way to handle this case?

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2010-02-24 13:55:16 +0800

stephenb gravatar image stephenb
54 1

This works. It seems like there must be a better way though.

  void setSelectedItems() {
    Set listItems = self.getSelectedItems();
    Set selectedItems = new HashSet( listItems.size() );
    for ( Object listItem : listItems ) {
      selectedItems.add( ( (Listitem) listItem ).getValue() );
    manager.setSelectedItems( selectedItems );
  void listItemOnCreate() {
      ( manager != null )
      && ( manager.getSelectedItems() != null )
      && manager.getSelectedItems().contains( self.value ) );
<listbox multiple="true"  onSelect="setBarcodeFields();">
  <listitem value="a" label="A" onCreate="listItemOnCreate()" />
  <listitem value="b" label="B" onCreate="listItemOnCreate()" />

link publish delete flag offensive edit

answered 2010-02-24 15:51:45 +0800

robertpic71 gravatar image robertpic71
1275 1


check this Thread.
There is databinding converter to handle multiple selects. Read the whole thread (no need for the referenced threads) to get the updates for the databindingcode.

The converter is written for selectItem, but handle Items. Maybe selectItems work also meanwhile.


link publish delete flag offensive edit
Your reply
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




Asked: 2010-02-24 08:24:13 +0800

Seen: 1,552 times

Last updated: Feb 24 '10

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