Thursday, July 25, 2013

ZK Listbox selecteditem vs selecteditems

Today i am going to discuss about two attributes of zk Listbox, one is selectedItem and another is selectedItems both looking same but do not think like that here we can say selectedItems means Single selection or multiple selection both thing supported here but in case of selectedItem only one item of Listbox will be selected.

May be above comparison will be not clear to everyone, so we have to digg more and go to the depth of these attributes, lets go to ZK Official Documentation and see what they are saying about these two attributes

For single selection state, ZK provides 2 kind of state. One is selected index and another is selected item of a model. We can create 2 properties in ViewModel for them respectively.

Here you can see selectedItem means only one item will be selected and bind from ViewModel
Some components support multiple selections, but it needs to be enabled before using it. The way to enable multiple selections depends on property's type you bind with "model" attribute. If the property type is Java Collection type such as List, Set, or Map , we should specify multiple="true" on the component to enable multiple selections. If a property's type is ListModel and it implements Selectable, we should call setMultiple(true) to enable it.

While selectedItems means multiple items could be selected and bind with one variables but you have to remember that in your zul you have to add multiple="true" attribute in Listbox inside ZUL file and in your ViewModel you have to call setMultiple(true) function.

1 comment: