-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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" /> </listbox>
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?
This works. It seems like there must be a better way though.
<zscript> 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() { self.setSelected( ( manager != null ) && ( manager.getSelectedItems() != null ) && manager.getSelectedItems().contains( self.value ) ); } </zscript> <listbox multiple="true" onSelect="setBarcodeFields();"> <listitem value="a" label="A" onCreate="listItemOnCreate()" /> <listitem value="b" label="B" onCreate="listItemOnCreate()" /> </listbox>
Hi,
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.
/Robert
Asked: 2010-02-24 08:24:13 +0800
Seen: 1,553 times
Last updated: Feb 24 '10