这是你可以做到的方式..
演示代码的 ZUL 文件..
<listbox model="@bind(vm.dataList)" >
<listhead>
<listheader value="A"></listheader>
<listheader value="B"></listheader>
<listheader value="C"></listheader>
</listhead>
<template name="model" var="mymodel">
<listitem>
<listcell>
<textbox value="@bind(mymodel.a)" />
</listcell>
<listcell>
<label value="@bind(mymodel.b)" />
</listcell>
<listcell>
<label value="@bind(mymodel.c)" />
</listcell>
</listitem>
</template>
</listbox>
</window>
演示代码的Java代码...
package com.team;
import java.util.ArrayList;
import java.util.List;
import org.zkoss.bind.annotation.AfterCompose;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.ContextParam;
import org.zkoss.bind.annotation.ContextType;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.zhtml.Messagebox;
import org.zkoss.zk.ui.Component;
import org.zkoss.zul.ListModelList;
public class MyListbox {
private ListModelList<Data> dataList;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
try {
dataList = new ListModelList<Data>();
Data data;
data = new Data("a1", "b1", "c1");
dataList.add(data);
data = new Data("a2", "b2", "c2");
dataList.add(data);
data = new Data("a3", "b3", "c3");
dataList.add(data);
dataList.addToSelection(dataList.get(0));
} catch (Exception e) {
}
}
@Command
public void ctrlKeyClick(@org.zkoss.bind.annotation.BindingParam("item") String ctekKeyCode ){
int keyCode =Integer.parseInt(ctekKeyCode);
String s = "";
switch(keyCode){
case 65: s = "Ctrl+A";break;
case 119: s = "F8";break;
case 83:s="Ctrl+S";break;
case 68:s="Ctrl+D";break;
}
Messagebox.show(s+" is pressed", "CtrlKey",
Messagebox.OK, Messagebox.EXCLAMATION);
System.out.println("I am clicked");
}
@Command
@NotifyChange("dataList")
public void addNewItem(){
Data data = new Data("", "", "");
dataList.add(data);
}
public ListModelList<Data> getDataList() {
return dataList;
}
public void setDataList(ListModelList<Data> dataList) {
this.dataList = dataList;
}
public class Data {
String a;
String b;
String c;
public String getA() {
return a;
}
public String getB() {
return b;
}
public String getC() {
return c;
}
public void setA(String a) {
this.a = a;
}
public void setB(String b) {
this.b = b;
}
public void setC(String c) {
this.c = c;
}
public Data(String a, String b, String c) {
super();
this.a = a;
this.b = b;
this.c = c;
}
}
}
在这里你可以检查这行代码..
dataList.addToSelection(dataList.get(0));
这将向您显示所选项目