-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I have a listbox with attributes multiple="true" and checkmark="true".
When the listbox is created (with no items because items only appears when a button is clicked) the checkmark to select multiple items is displayed in the listheader.
But when I fill the listbox with data (binder.loadComponent(LBFicheros)) the checkbox disappears and a radiobutton is displayed in each row. I checked if the listbox for some reason changes to multiple="false" but is not so, listbox is still multiple.
Any idea why is this happening?
My listbox:
<listbox id="LBFicheros" multiple="true" checkmark="true" width="100%" vflex="1" mold="paging" autopaging="true" model="@{VentanaFicheros$composer.listaBeans}"> <listhead sizable="true"> ... </listhead> <listitem id="fila" self="@{each=ServidorBean}" value="@{ServidorBean}"> <listcell label="@{ServidorBean.Tabla}" tooltiptext="@{ServidorBean.Tabla}" style="text-align:left;white-space:nowrap"/> .... </listitem> </listbox>
Neus, please could you post the solution to the problem, or a description of your error, for future readers?
I was doing something wrong..I don't think that naybody will do that too :P (in some part of my application I was setting multiple to false)
But...now I update to ZK 6 and it is happening again!And it seems that this time is not my fault!
Don't know why is this happening...But setting listbox multiple="true" and checkmrk ="true" doesn't work. It shows a radiobutton and no multiple selection is available.
I found and example in ZK Fiddle in which is happening the same...
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk>
<zscript>
class customListbox extends org.zkoss.zul.Listbox {
public Listitem getSelectedItem() {
Listitem li = super.getSelectedItem();
if (li == null) {
// get first item if no one is selected
li = getItemAtIndex(0);
}
if (li == null) {
// create an invalid item if no item in listbox
li = new Listitem();
People p = new People();
p.setName("Invalid Name");
p.setAge(999);
li.setValue(p);
}
return li;
}
}
page.getComponentDefinition("listbox", true).setImplementationClass(customListbox.class);// the class of people
class People {
String name;
int age;
public void setName(String name) {
this.name = name;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}// create data list
List lpeoples = new ArrayList();
List lpeoplesEmpty = new ArrayList();
for (int i = 15;i != 20;i ++) {
People p = new People();
p.setName("Name "+i);
p.setAge(i);
lpeoples.add(p);
}
</zscript>
<html><![CDATA[
<ol>
<li> check / uncheck the "clear data" checkbox to clear / restore the data</li>
<li> the value will show in textbox when header double_clicked</li>
<li> if an item selected, selected item is that one</li>
<li> if no item selected, selected item is the first item</li>
<li> if no item in listbox, will create an invalid one</li>
</ol>
]]>
</html>
<vbox>
<checkbox label="clear data">
<attribute name="onCheck">
if (self.checked)
listOfPeople.setModel(new BindingListModelList(lpeoplesEmpty, true));
else
listOfPeople.setModel(new BindingListModelList(lpeoples, true));
</attribute>
</checkbox>
<hbox>
name: <textbox id="sName" />
</hbox>
<hbox>
age: <textbox id="sAge" />
</hbox>
</vbox>
<listbox id="listOfPeople" checkmark="true" multiple="true" model="@{lpeoples}"
value="@{peopleData}" selectedItem="@{selectedPeople}">
<listhead sizable="true">
<attribute name="onDoubleClick">
People p = (People)listOfPeople.getSelectedItem().getValue();
sName.setValue(p.getName());
sAge.setValue(p.getAge().toString());
</attribute>
<listheader label="Name"/>
<listheader label="Age"/>
</listhead>
<listitem self="@{each=people}" value="@{people}">
<listcell label="@{people.name}"/>
<listcell label="@{people.age}"/>
</listitem>
</listbox>
</zk>
In this example checkmark and multiple are setted to true but if you run it using Zk 6.0 only radiobutton appears and you can't select more than one item!
In ZK6, the multiple flag of the llistbox may get overwritten by the multiple flag of the listmodel. These are the possibilities to circumvent it:
- provide a "real" ListModel as model and set multiple=true there
- with ZK6 binding you can bind selectedItems instead of selectedItem, then multiple=true is set automatically
- use a converter like that on the model to fix that behavior:
/** * Fix multiple selection state. * * @author matze */ public class MultiSelectionConverter extends ListModelConverter { private static final long serialVersionUID = 1L; @Override public Object coerceToUi(Object val, Component comp) { Object bean = super.coerceToUi(val, comp); AbstractListModel<?> model = (AbstractListModel<?>) bean; Listbox listbox = (Listbox) comp; if (listbox.isMultiple() && !model.isMultiple()) { model.setMultiple(true); } return bean; } }
I'm changing to ZK6 binding.
Matze2 said that with ZK6 Bind if selectedItems are bind multiple="true" is set automatically.
I tried it and multiple="true"wasn't set.
So I hope some of you can help me finding what I'm not doing well:
This is my listbox:
<listbox nonselectableTags="*" id="LBFicheros" multiple="true" checkmark="true" mold="paging" autopaging="true" model="@load(vm.items)" selectedItems="@bind(vm.selected)">
private Set <ServidorBean> selected; public Set<ServidorBean> getSelected() { System.out.println("Entra en getSelected"); return selected; } public void setSelected(Set<ServidorBean> selected){ System.out.println("Entra en setSelected"); this.selected = selected; }
With this code multiple selection is not enabled and radiobuttons are shown instead of checkboxes.
If I set multiple="true" in the ListModelList it works OK but I understood (maybe I'm wrong) that it is not necessary if selectedItems are binded.
Things changed during the ZK6 development. Currently my multi-selection listboxes look like the following:
<listbox multiple="true" selectedItems="@bind(vm.selectedEntries)" model="@load(vm.entries)">
Ok, I reproduce your listbox:
<listbox id="LBFicheros" multiple="true" model="@load(vm.items)" selectedItems="@bind(vm.selected)">
I repeat that setting multiple to listmodellist works.
Yes, this looks ok. Do you use ZK6 release?
And how does your getItems() looks like?
Asked: 2012-01-05 09:00:26 +0800
Seen: 1,424 times
Last updated: Feb 21 '12