Listbox绑定数据--》list.setModel(new ListModelList<InStorageInfo>(inStorageInfos));
Listbox显示数据--》list.setItemRenderer(new InStorageInfoListItemRenderer()); //感觉跟android中的adapter类似
通过MouseEvent获取被点击的button,然后通过getParent得到listitem
前端:
<listbox id="list" mold="paging" pageSize="10"
emptyMessage="No saleinfo found in the result">
<listhead>
<listheader label="Detail" />
</listhead>
<template name="model">
<listitem>
</listitem>
</template>
</listbox>
后端:
public class InStorageInfoListItemRenderer implements ListitemRenderer<InStorageInfo> {
@Override
public void render(Listitem item, InStorageInfo data, int index) throws Exception {
Listcell detail=new Listcell();
final Button detailBtn=new Button();
detailBtn.setLabel("Detail");
detailBtn.setAttribute("info", data);
detail.appendChild(detailBtn);
detail.setParent(item);
ComponentsCtrl.applyForward(detailBtn, "onClick=onClickDetail");
item.setAttribute("data", data);
}
}
public class InStorageInfoCtrl extends GenericForwardComposer implements Serializable {
private Listbox list;
public void onClickDetail(MouseEvent event) {//in order to get button,must use MouseEvent
Listitem listitem = (Listitem) event.getTarget().getParent().getParent();
InStorageInfo info = (InStorageInfo) listitem.getAttribute("data");
// Executions.sendRedirect("/zul/detail.zul?id=" + info.getID());
Map<String,Integer> map=new HashMap<String, Integer>();
map.put("ID", info.getID());
Window window=(Window) Executions.createComponents("/zul/detail.zul", inStorageWin, map);
window.doModal();
}
}