0

How to set: self="@{each=row}" in java files?

asked 2009-01-07 02:12:34 +0800

evpole gravatar image evpole
481 2

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 ?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2009-01-07 09:55:27 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2009-01-13 03:21:00 +0800

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);
     } 
}

link publish delete flag offensive edit

answered 2009-01-07 10:12:26 +0800

hideokidd gravatar image hideokidd
750 1 2

updated 2009-01-09 09:01:57 +0800

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);
                }
}

link publish delete flag offensive edit

answered 2009-01-09 07:50:30 +0800

evpole gravatar image evpole
481 2

Thanks very much,dear hideokidd !
that helped me a lot !

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-01-07 02:12:34 +0800

Seen: 302 times

Last updated: Jan 09 '09

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More