answered
2014-12-15 09:57:14 +0800
terrytornado 9393 ● 3 ● 7 ● 16
http://www.oxitec.de/
Do not use the 'checkmark' attribute. Make your own implementation.
Only a small sample.
zul:
<zk xmlns="<a href=" http:="" www.zkoss.org="" 2005="" zul"="">http://www.zkoss.org/2005/zul" xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:w="http://www.zkoss.org/2005/zk/client"
xmlns:n="http://www.zkoss.org/2005/zk/native"
xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">
<window width="500px" height="300px">
<listbox id="lbListObject" mold="paging" emptyMessage="Không có dữ liệu" pageSize="5"
apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('com.mysamples.listbox.ListboxCheckAllVM')">
<listhead>
<listheader>
<checkbox id="chkb_all" label="check all" />
</listheader>
<listheader label="Lastname" />
<listheader label="Firstname" />
</listhead>
<listitem></listitem>
</listbox>
</window>
</zk>
VM:
public class ListboxCheckAllVM {
private Listbox listbox;
private int pageSize = 5;
@Init
public void initSetup() {
}
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
if (view instanceof Listbox) {
this.listbox = (Listbox) view;
}
if (this.listbox != null) {
this.listbox.getFellow("chkb_all").addEventListener("onCheck", new CheckAllListener());
this.listbox.setPageSize(this.pageSize);
this.listbox.setModel(new ListModelList<Person>(getAllPersons()));
this.listbox.setItemRenderer(new CheckAllItemRenderer());
}
}
/**
* Inner Listener class.<br>
* onCheck for the 'mark all for deleting' Checkbox.
*
*/
private final class CheckAllListener implements SerializableEventListener<Event> {
private static final long serialVersionUID = 1L;
@Override
public void onEvent(Event event) throws Exception {
Checkbox ckb = (Checkbox) event.getTarget();
if (ckb.isChecked()) {
checkAllItems(true);
} else {
checkAllItems(false);
}
}
}
/**
* EN: Checks/unchecks all items as marked for deleting.<br>
*/
@SuppressWarnings("unchecked")
public void checkAllItems(boolean checkAll) {
List<Listitem> list = this.listbox.getItems();
if (list.size() > 0) {
for (Listitem li : list) {
if (li.getFirstChild().getFirstChild() instanceof Checkbox) {
Checkbox cb = (Checkbox) li.getFirstChild().getFirstChild();
cb.setChecked(checkAll);
}
}
}
this.listbox.invalidate();
}
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
private String lastname;
private String firstname;
public Person() {
}
public Person(String _lastname, String _firstname) {
this.lastname = _lastname;
this.firstname = _firstname;
}
public String getLastname() {
return this.lastname;
}
public void setLastname(String _lastname) {
this.lastname = _lastname;
}
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String _firstname) {
this.firstname = _firstname;
}
}
private List<Person> getAllPersons() {
List<Person> list = new ArrayList<Person>();
list.add(new Person("Doe1", "John"));
list.add(new Person("Doe2", "John"));
list.add(new Person("Doe3", "John"));
list.add(new Person("Doe4", "John"));
list.add(new Person("Doe5", "John"));
list.add(new Person("Doe6", "John"));
list.add(new Person("Doe7", "John"));
list.add(new Person("Doe8", "John"));
list.add(new Person("Doe9", "John"));
return list;
}
}
ListItemRenderer:
public class CheckAllItemRenderer implements ListitemRenderer<Person>, Serializable {
private static final long serialVersionUID = 1L;
private Listbox lb;
@Override
public void render(Listitem item, Person data, int index) throws Exception {
Person obj = (Person) data;
Listcell lc;
Label lb;
Checkbox cb;
// Delete Checkbox
lc = new Listcell();
cb = new Checkbox();
cb.setParent(lc);
cb.setChecked(false);
cb.setStyle("padding-left: 3px;");
cb.setTooltiptext("Mark for delete");
lc.setParent(item);
// Lastname
lc = new Listcell();
lb = new Label();
lb.setValue(obj.getLastname());
lb.setParent(lc);
lc.setParent(item);
// Firstname
lc = new Listcell();
lb = new Label();
lb.setValue(obj.getFirstname());
lb.setParent(lc);
lc.setParent(item);
}
}
best
Stephan