Suggested case list:
Using timer to refresh a grid
383guest172.69.33.12125nk0uiMay 7, 2020 7:23:47 AMlinkuser model to move item to another listbox
120guest162.158.193.148d0n3krApr 2, 2020 5:28:28 AMlinkDisabled list item row passed to VM-1981
296fatih123160.83.36.13025nk0uiFeb 13, 2018 4:25:44 PMlinkDisabled list item row passed to VM-1981
295fatih123160.83.36.13025nk0uiFeb 13, 2018 4:25:16 PMlinkDisabled list item row passed to VM-1981
294fatih123160.83.36.13225nk0uiFeb 13, 2018 3:30:44 PMlinkgrid sample with ListModel/RowRenderer
816guest80.82.2.1312vah9ajFeb 21, 2017 11:42:21 AMlinkgrid sample with ListModel/RowRenderer
809guest175.98.113.1622vah9ajJan 26, 2017 9:19:33 AMlinkgrid sample with ListModel/RowRenderer
196guest79.185.142.402vah9ajApr 26, 2014 10:53:57 PMlinkgrid sample with ListModel/RowRenderer
195guest79.185.142.402vah9ajApr 26, 2014 10:53:54 PMlinkgrid sample with ListModel/RowRenderer
194guest79.185.142.402vah9ajApr 26, 2014 10:53:51 PMlinkgrid sample with ListModel/RowRenderer
193guest79.185.142.402vah9ajApr 26, 2014 10:53:48 PMlinkgrid sample with ListModel/RowRenderer
192guest79.185.142.402vah9ajApr 26, 2014 10:53:44 PMlinkgrid sample with ListModel/RowRenderer
191guest79.185.142.402vah9ajApr 26, 2014 10:53:40 PMlinkHierarchy table without using ZK PE/EE
1aaknai151.28.135.2131s871daJul 29, 2013 11:02:46 PMlinkgrid sample with ListModel/RowRenderer
128aaknai151.28.135.2132vah9ajJul 29, 2013 7:20:00 PMlinkuser model to move item to another listbox
1TonyQ114.25.109.94d0n3krApr 21, 2012 10:43:27 AMlinkUsing timer to refresh a grid
1TonyQ220.133.44.3725nk0uiFeb 17, 2012 3:17:34 AMlinkFire a event from child iframe
1TonyQ220.133.44.372eupjotFeb 3, 2012 5:04:52 AMlinkTextbox input restriction sample
1TonyQ72.21.245.2431b3nlr0Dec 20, 2011 10:09:10 AMlinkTest web core taglib in ZUL
1TonyQ198.203.175.175ofqkemDec 17, 2011 3:36:08 AMlinkLatest 10 Fiddles :
constraint binding textbox
3guest172.68.151.16220peldaDec 5, 2025 5:08:19 PMlinkAnother new ZK fiddle
2guest172.68.151.16320peldaDec 5, 2025 5:07:51 PMlinkAnother new ZK fiddle
1guest172.68.151.16220peldaDec 5, 2025 5:07:32 PMlinkAnother new ZK fiddle
1peggypeng172.71.154.99364f4neDec 5, 2025 9:24:31 AMlinktooltip example
2guest104.22.23.13rc1ntoDec 4, 2025 2:23:45 PMlinkAnother new ZK fiddle
1guest172.69.134.2277t7602Dec 4, 2025 1:40:46 PMlinkAnother new ZK fiddle
1peggypeng104.22.17.1802df6e3oDec 4, 2025 8:41:29 AMlinkonClose
1peggypeng172.68.87.248j8kd8aDec 3, 2025 4:10:26 AMlinkAnother new ZK fiddle
1peggypeng172.69.134.2271rm7f4eNov 26, 2025 3:31:24 AMlinkZK-5912-Suggestion
2rebeccalai104.22.20.1442qrmiiuNov 26, 2025 2:07:15 AMlinkAnother new ZK fiddle
1guest172.69.33.943fvuq4cJul 13, 2023 1:42:05 PMlinkresources
index.zulzul<zk xmlns:w="client" xmlns:ca="client/attribute">
<style>
/*using css to show / hide labels and textboxes depending on listitem selection status*/
/*a listitem always has the z-listitem class, but will receive and loose the z-listitem-selected
class depending on selection status*/
.z-listitem .custom-label{
display: inline-block;
}
.z-listitem .custom-textbox{
display: none;
}
.z-listitem-selected .custom-label{
display: none;
}
.z-listitem-selected .custom-textbox{
background-color: LemonChiffon;
display: inline-block;
}
</style>
<script><![CDATA[
function selectNextSiblingInput(wgt){
setTimeout(function(){ //setTimeout in order to execute this code AFTER resolve the current JS stack (which will change the selection state and visibility state)
var targetTextbox = wgt.nextSibling; //always assume that the textbox is the next element after the label
targetTextbox.focus(); // set focus into the textbox
/*optional: set the cursor selection to end of box, or to select whole text for quick typing*/
var currentValue = targetTextbox.getValue(); //retrieve string value
//targetTextbox.select(0,currentValue.length) /*select whole text*/
targetTextbox.select(currentValue.length,currentValue.length) // OR put cursor at the end of text
},0);
}
zk.afterLoad("zul.sel", function(){
zul.sel.ListitemFocusExt = zk.$extends(zul.sel.Listitem,{
focus_: function focus_(timeout) {
var mesh = this.getMeshWidget();
this._doFocusIn();
mesh._syncFocus(this);
mesh.focusA_(mesh.$n('a'), timeout);
/*option 1: lookup first textbox in descendants and focus it*/
/*if(zk.$(jq(this).find(".z-textbox"))){
zk.$(jq(this).find(".z-textbox")).focus();*/
/*}*/
/*option 2: use client-side attribute to locate a descendant matching the last known attribute*/
if(mesh._lastKnownCellFocusId){
var target = zk.$(jq(this).find("input[data-focusid='"+mesh._lastKnownCellFocusId+"']"));
target.focus();
/*optional: set the cursor selection to end of box, or to select whole text for quick typing*/
var currentValue = target.getValue(); //retrieve string value
//targetTextbox.select(0,currentValue.length) /*select whole text*/
target.select(currentValue.length,currentValue.length) // OR put cursor at the end of text
setTimeout(function(){
delete mesh._lastKnownCellFocusId;
},0);
}
return true;
}
});
zul.sel.ListcellFocusExt = zk.$extends(zul.sel.Listcell,{
doKeyDown_: function doKeyDown_(evt) {
var key = evt.key,
listbox = this.getListbox();
if (listbox.inSelectMold()) return;
if (listbox && (evt.domTarget.tagName == 'TD' )) {
var goToItemStep = 0,
parent = this.parent,
a11yMeshUtil = zul.mesh.a11yMeshUtil;
switch (key) {
case 'ArrowLeft':
var sib = a11yMeshUtil.getVisibleSibling(this, -1);
if (sib) {
this._resetTabindex();
sib._focusContent();
}
break;
case 'ArrowRight':
var sib = a11yMeshUtil.getVisibleSibling(this, 1);
if (sib) {
this._resetTabindex();
sib._focusContent();
}
break;
case ' ':
case 'Enter':
if (zk.isLoaded('zkex.sel') && parent.$instanceof(zkex.sel.Listgroup)) parent._openItem(!parent._open);
break;
}
}
if (listbox && (evt.domTarget.tagName == 'TD' || evt.domTarget.tagName == 'INPUT' )) {
var goToItemStep = 0,
parent = this.parent,
a11yMeshUtil = zul.mesh.a11yMeshUtil;
switch (key) {
case 'ArrowUp':
goToItemStep = -1;
break;
case 'ArrowDown':
goToItemStep = 1;
break;
}
}
if (goToItemStep != 0) {
this._resetTabindex();
evt.stop();
var activeElement = document.activeElement,
nextItem = zul.mesh.a11yMeshUtil.getVisibleSibling(parent, goToItemStep);
if(activeElement && activeElement.getAttribute("data-focusid")){
listbox._lastKnownCellFocusId = activeElement.getAttribute("data-focusid");
}
if (nextItem && zk.isLoaded('zkex.sel') && (nextItem.$instanceof(zkex.sel.Listgroup) || nextItem.$instanceof(zkex.sel.Listgroupfoot))) {
nextItem.focusFirstChild();
return;
}
if (!jq.nodeName(evt.domTarget, 'a')) listbox.focus();
evt.domTarget = activeElement;
evt.target = listbox;
listbox._focusItem = parent;
listbox._doKeyDown(evt);
}
}
});
});
]]></script>
<borderlayout id="empList" viewModel="@id('vm') @init('pkg$.EmpList3MVVM')" vflex="1" hflex="1">
<north id="north1">
<div align="center" width="100%">
<label value="Employee List" sclass="program-title"/>
</div>
</north>
<center id="b1ListPanel" border="none" autoscroll="true">
<div align="center" vflex="1">
<vbox width="700px" vflex="1">
<!-- model init can be used with ListModelList, since it only needs to be loaded once -->
<!-- selection trigger can be done with a command binding, or by listening to VM#setSelectedItem if binding on selectedItem -->
<!-- listening to up/down to restore focus on the Listbox. This causes the next up/down to perform regular selection on listbox -->
<listbox id="b1Listbox" nonselectableTags=""
model="@init(vm.container.empList)" onSelect="@command('doSelection', previousSelectedObjects=event.previousSelectedObjects)"
multiple="false" sizedByContent="true" span="true"
mold="paging" autopaging="true" vflex="1">
<listhead sizable="true">
<listheader label="Emp. No." hflex="3"/>
<listheader label="Name" hflex="10"/>
<listheader label="Position" hflex="10"/>
<listheader label="Salary" hflex="10" align="right"/>
</listhead>
<template name="model">
<listitem w:use="zul.sel.ListitemFocusExt">
<listcell w:use="zul.sel.ListcellFocusExt">
<label value="@load(each.empNo)" w:onClick="selectNextSiblingInput(this);" sclass="custom-label" width="100%"/>
<textbox inplace="true" value="@bind(each.empNo)" sclass="custom-textbox" ca:data-focusid="cell1" width="100%"/>
</listcell>
<listcell w:use="zul.sel.ListcellFocusExt">
<label value="@load(each.empName)" w:onClick="selectNextSiblingInput(this);" sclass="custom-label" width="100%"/>
<textbox inplace="true" value="@bind(each.empName)" sclass="custom-textbox" ca:data-focusid="cell2" width="100%"/>
</listcell>
<listcell w:use="zul.sel.ListcellFocusExt">
<label value="@load(each.empPosition)" w:onClick="selectNextSiblingInput(this);" sclass="custom-label" width="100%" />
<textbox inplace="true" value="@bind(each.empPosition)" sclass="custom-textbox" ca:data-focusid="cell3" width="100%" />
</listcell>
<listcell w:use="zul.sel.ListcellFocusExt">
<label value="@load(each.salary)" w:onClick="selectNextSiblingInput(this);" sclass="custom-label" width="100%"/>
<doublebox inplace="true" value="@bind(each.salary)" sclass="custom-textbox" ca:data-focusid="cell4" width="100%"/>
</listcell>
</listitem>
</template>
</listbox>
</vbox>
</div>
</center>
</borderlayout>
</zk>
EmpList3MVVM.javajava
import java.io.Serializable;
import java.util.List;
import java.util.Set;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.Init;
import org.zkoss.lang.Strings;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.SelectEvent;
import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zk.ui.util.Notification;
import org.zkoss.zul.ListModelList;
public class EmpList3MVVM implements Serializable {
private static final long serialVersionUID = 1L;
public static class Emp implements Serializable {
private static final long serialVersionUID = 1L;
private Integer empId;
private String empNo;
private String empName;
private String empPosition;
private Integer salary;
private DataContainer container;
public Emp(){}
public Emp(Integer empId,String empNo,String empName,String empPosition,Integer salary,DataContainer container) {
this.empId = empId;
this.empNo = empNo;
this.empName = empName;
this.empPosition = empPosition;
this.salary = salary;
this.container = container;
}
public Integer getEmpId() {
return empId;
}
public void setEmpId(Integer empId) {
this.empId = empId;
}
public String getEmpNo() {
return empNo;
}
public void setEmpNo(String empNo) {
this.empNo = empNo;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpPosition() {
return empPosition;
}
public void setEmpPosition(String empPosition) {
this.empPosition = empPosition;
}
public Integer getSalary() {
return salary;
}
public void setSalary(Integer salary) {
this.salary = salary;
}
public boolean isSelected() {
return container == null ? false : container.getSelectedEmp() == this;
}
public boolean isNotSelected() {
return !isSelected();
}
}
public static class DataContainer implements Serializable {
private static final long serialVersionUID = 1L;
/*not necessary to bind to Listbox#selectedItem when delegating selection to ListModelList*/
// private Emp selectedEmp;
/* replacing List with ListModelList permit the use of ListModelList feature, and avoid redrawing on every operation*/
private ListModelList<Emp> empList = new ListModelList<Emp>();
public Emp getSelectedEmp() {
return empList.getSelection().iterator().next();
}
// }
public void setSelectedEmp(Emp emp) {
empList.clearSelection();
empList.addToSelection(emp);
}
/*only called once, due to changing to @init() binding in the view*/
public List<Emp> getEmpList() {
return empList;
}
/* usually not called. it is not expected that the view sends a whole copy of the model to the VM*/
/*public void setEmpList(ListModelList<Emp> empList) {
this.empList = empList;
}*/
public void add(Emp emp) {
empList.add(emp);
}
}
private DataContainer container;
public DataContainer getContainer() {
return container;
}
public void setContainer(DataContainer container) {
this.container = container;
}
@Init
public void init(@ContextParam(ContextType.VIEW) Component view) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
container = new DataContainer();
Emp emp = new Emp(1,"TW001","John Smith","Staff",32000,container);
container.add(emp);
container.setSelectedEmp(emp);
emp = new Emp(2,"TW002","Hellen Wilson","Staff",34000,container);
container.add(emp);
emp = new Emp(4,"TW004","Tom Brown","Staff",32000,container);
container.add(emp);
emp = new Emp(24,"TW024","Taylor Swift","Manager",50000,container);
container.add(emp);
emp = new Emp(30,"TW030","Albert Young","CEO",100000,container);
container.add(emp);
}
@Command
public void doSelection(@BindingParam("previousSelectedObjects") Set<Emp> previousSelectedObjects) {
if(previousSelectedObjects.size() > 0) {
Emp previousSelection = previousSelectedObjects.iterator().next();
boolean isValid = validateEmp(previousSelection);
if(!isValid) {
container.empList.clearSelection();
container.empList.addToSelection(previousSelection);
Notification.show("Warning: invalid row data", Notification.TYPE_ERROR, null, null, 0);
}
}
Clients.log("do something with selection: " + container.empList.getSelection());
}
private boolean validateEmp(Emp previousSelection) {
return !Strings.isEmpty(previousSelection.getEmpName());
}
}