-
FEATURED COMPONENTS
First time here? Check out the FAQ!
in zul files, we could bind a listbox to a model like this:
--------------------------------------------------------------------
<listbox width="95%" fixedLayout="true" model="@{model}" >
<listhead sizable="true">
<listheader label="InfoId" width="35px" />
<listheader label="FileId" width="35px" />
<listheader label="Text" width="500px" />
</listhead>
<listitem self="@{each=row}">
<listcell label="@{row.infoid}" />
<listcell label="@{row.fileid}" />
<listcell label="@{row.name}" />
</listitem>
</listbox>
------------------------------------------------------------
But I need to create the listbox danymically in java files, in this case , how could i set the self attribute ?
Hi
You can see "Two-Columns Example" in the small talk data binding
I also provide a simple example for listbox to fit your requirement.
in zul file
<winodw id="win" use="AddListbox"/> <zscript> win.add(win); </zscript>
in AddListbox.java (part)
public void add(Window win){ Listbox lbx = new Listbox(); ListModelList lm = new ListModelList (model); Listhead lh = new Listhead(); Listheader lhr1 = new Listheader(); Listheader lhr2 = new Listheader(); Listheader lhr3 = new Listheader(); lbx.setWidth("95%"); lbx.setFixedLayout(true);\ lh.setSizable(true); lhr1.setLabel("InfoId"); lhr1.setWidth("35px"); lhr2.setLabel("FileId"); lhr2.setWidth("35px"); lhr3.setLabel("Text"); lhr3.setWidth("500px"); lhr1.setParent(lh); lhr2.setParent(lh); lhr3.setParent(lh); lh.setParent(lbx); lbx.setParent(win); String model[][]={{"11","12","13"},{"21","22","23"}}; ListModel strset = new SimpleListModel(model); lbx.setModel(strset); lbx.setItemRenderer(new ListitemRenderer()); }
in listitemRenderer.java
public class listitemRenderer implements ListitemRenderer{ public void render(Listitem li, java.lang.Object data) { String[] _data = (String[])data; for (int i=0;i<3;i++){ Listcell lc = new Listcell(); new Label(_data<i >).setParent(lc); lc.setParent(li); } }
An example without listitemrenderer :
in ZUL file
<winodw id="win" use="AddListbox"/> <zscript> win.add(win); </zscript>
in AddListbox.java (part)
public void add(Window win){ String model[][]={{"11","12","13"},{"21","22","23"}}; Listbox lbx = new Listbox(); ListModelList lm = new ListModelList (model); Listhead lh = new Listhead(); Listheader lhr1 = new Listheader(); Listheader lhr2 = new Listheader(); Listheader lhr3 = new Listheader(); lbx.setWidth("95%"); lbx.setFixedLayout(true); //render listhead lh.setSizable(true); lhr1.setLabel("InfoId"); lhr1.setWidth("35px"); lhr2.setLabel("FileId"); lhr2.setWidth("35px"); lhr3.setLabel("Text"); lhr3.setWidth("500px"); lhr1.setParent(lh); lhr2.setParent(lh); lhr3.setParent(lh); lh.setParent(lbx); lbx.setModel(lm); lbx.setParent(test_div); //render listitem Listitem li = new Listitem(); li.setParent(lbx); for (int i=0;i<model.length;i++){ Listcell lc = new Listcell(); lc.setParent(li); for (int j=0;j<model[i].length;j++) new Label(model[i][j]).setParent(lc); } }
Asked: 2009-01-07 02:12:34 +0800
Seen: 302 times
Last updated: Jan 09 '09