Search code examples
zk

Why can't I use multiple selection with listbox in zk framework?


I followed zk demo to create listbox with multiple selection. Here is my zul file:

<window title="demo"
    xmlns:h="http://www.w3.org/1999/xhtml"
    xmlns="http://www.zkoss.org/2005/zul"
    apply="com.viettel.voffice.controller.ListboxController">
<listbox id="lb" model="${$composer.list}" multiple="true" checkmark="true" mold="paging" pageSize="10">
    <listhead>
        <listheader label="STT"/>
        <listheader label="Name"/>
    </listhead>
    <template name="model">
        <listitem>
            <listcell label="${forEachStatus.index}"/>
            <listcell label="${each}"/>
        </listitem>
    </template>
</listbox>

Controller:

public class ListboxController extends SelectorComposer<Component> {

@Wire
private Listbox lb;

private ListModelList list;

@Override
public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);

    List listData = new BigList(1000);
    list = new ListModelList(listData);
    lb.setModel(list);
    lb.renderAll();
    lb.setMultiple(true);
}

@Override
public ComponentInfo doBeforeCompose(Page page, Component parent, ComponentInfo compInfo) {
    return super.doBeforeCompose(page, parent, compInfo);
}

public ListModelList getList() {
    return list;
}

BigList.java:

public class BigList extends AbstractList<Integer> {

private int size;

public BigList(int sz) {
    if (sz < 0) {
        throw new IllegalArgumentException("Negative not allowed: " + sz);
    }
    size = sz;
}

public int size() {
    return size;
}

public Integer get(int j) {
    return Integer.valueOf(j);
}

}

And here is what zk display:

https://farm4.staticflickr.com/3919/15032438702_fb403efc70_o.png

Why doesn't listbox display multiple selection?

I have just solved it. Just add this line: model.setMultiple(true); :D


Solution

  • You made little mistake you have to add this in afterCompose() method

    list.setMultiple(true);