-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello everybody
I read at http://zkfiddle.org/sample/1t9kc1e/6-Listbox-Render-on-Demand#source-1
and do it the same. As you see at my code:
this is my view:
<div apply="de.forsthaus.webui.blog.UserListCtrl"> <button label="Load DB" id="bttLoad" width="120px" height="25px" /> <hlayout spacing="0" height="400px"> <listbox id="listUser" width="600px" height="700px"> <listhead> <listheader label="User Name" align="left" /> <listheader label="Description" align="left" /> <listheader label="Email" align="left" /> </listhead> </listbox> </hlayout> </div>
and this is UserListCtrl Controller:
package de.forsthaus.webui.blog; import mcrt.model.UserServices; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Listbox; import de.forsthaus.webui.blog.DummyUser; import de.forsthaus.webui.blog.UserRenderer; public class UserListCtrl extends GenericForwardComposer { private static final long serialVersionUID = 1L; private Listbox listUser; private ListModelList listModel; public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); listModel = new ListModelList(DummyUser.getPersonList()); listUser.setItemRenderer(new UserRenderer()); } public void onClick$bttLoad() { listUser.setModel(listModel); } public void onAfterRender$listGrid() { UserServices uservices = new UserServices(); for (int i = 0; i < uservices.findAll().size() - 1; i++) { listUser.renderItem(listUser.getItemAtIndex(i)); } } }
this is class DummyUser
package de.forsthaus.webui.blog; import java.util.ArrayList; import mcrt.model.User; import mcrt.model.UserServices; public class DummyUser { private static ArrayList<User> personList = new ArrayList<User>(); static { setPersonList(); } public static ArrayList<User> getPersonList() { return personList; } private static void setPersonList() { UserServices uservices = new UserServices(); for (int i = 0; i < uservices.findAll().size() - 1; i++) { User personx = new User(); personx.setsDescription(uservices.findAll().get(i) .getsDescription()); personList.add(new User(uservices.findAll().get(i).getiUserID(), uservices.findAll().get(i).getsUserName(), uservices .findAll().get(i).getsUserPass(), uservices .findAll().get(i).getiRole(), uservices.findAll() .get(i).getsDescription(), uservices.findAll() .get(i).getsRole(), uservices.findAll().get(i) .getsEmail(), uservices.findAll().get(i) .getsHashCode())); } } }
This is User Model
package mcrt.model; public class User { private String iUserID ; private String sUserName; private String sUserPass; private String iRole; private String sDescription; private String sRole; private String sEmail; private String sHashCode; public User(String iUserID,String sUserName, String sUserPass, String iRole,String sDescription,String sRole,String sEmail,String sHashCode) { this.iUserID = iUserID; this.sUserName = sUserName; this.sUserPass = sUserPass; this.iRole = iRole; this.sDescription = sDescription; this.sRole = sRole; this.sEmail = sEmail; this.sHashCode = sHashCode; } public User() { } public String getiUserID() { return iUserID; } public void setiUserID(String iUserID){ this.iUserID = iUserID; } public String getsUserName() { return sUserName; } public void setsUserName(String sUserName){ this.sUserName = sUserName; } public String getsUserPass(){ return sUserPass; } public void setsUserPass(String sUserPass){ this.sUserPass = sUserPass; } public String getiRole() { return iRole; } public void setiRole(String iRole){ this.iRole = iRole; } public String getsDescription() { return sDescription; } public void setsDescription(String sDescription){ this.sDescription = sDescription; } public String getsRole() { return sRole; } public void setsRole(String sRole){ this.sRole = sRole; } public String getsHashCode() { return sHashCode; } public void setsHashCode(String sHashCode){ this.sHashCode = sHashCode; } public String getsEmail(){ return sEmail; } public void setsEmail(String sEmail){ this.sEmail = sEmail; } }
and this is UserRenderer
package de.forsthaus.webui.blog; import mcrt.model.User; import org.zkoss.zul.Listcell; import org.zkoss.zul.Listitem; import org.zkoss.zul.ListitemRenderer; public class UserRenderer implements ListitemRenderer { public void render(Listitem item, Object data) throws Exception { User person = (User) data; item.setValue(person); new Listcell(String.valueOf(person.getiRole())); new Listcell(String.valueOf(person.getiUserID())); new Listcell(String.valueOf(person.getsDescription())); new Listcell(String.valueOf(person.getsEmail())); new Listcell(String.valueOf(person.getsHashCode())); new Listcell(String.valueOf(person.getsRole())); new Listcell(String.valueOf(person.getsUserName())); new Listcell(String.valueOf(person.getsUserPass())); } }
this happen when i click to show data:
PLEASE HELP ME :(
. . . <listhead> <listheader label="User Name" align="left" sort="auto"/> . . .
best
Stephan
last question:
now I want to sort in listbox ? how can I do it ?
i see at http://books.zkoss.org/wiki/ZK_Component_Reference/Data/Listbox and apply to my template
but it have error :
org.zkoss.zk.ui.metainfo.PropertyNotFoundException: Method setSortDirection not found for class org.zkoss.zul.Listhead
org.zkoss.zk.ui.metainfo.PropertyNotFoundException: Method setSortDirection not found for class org.zkoss.zul.Listhead
org.zkoss.lang.SystemException: org.xml.sax.SAXParseException; systemId: file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/BaseWeb/pages/user/test.zul; lineNumber: 86; columnNumber: 50; Element type "listheader" must be followed by either attribute specifications, ">" or "/>".
Please help me !!!
public void render(Listitem item, Object data) throws Exception { User person = (User) data; Listcell lc; . . . // username lc = new Listcell( String.valueOf( person.getUserName() )): lc.setParent(item); // description lc = new Listcell( String.valueOf( person.getDescription() )): lc.setParent(item); // email lc = new Listcell( String.valueOf( person.getEmail() )): lc.setParent(item); . . .
Defining ONE 'Listcell lc;' is definitively enough because you do by every new Listcell create a 'NEW' object with lc = new Listcell(...
@Stephan: no I dont use repeat "lc" as you write, I put another lc :
as you see:
public void render(Listitem item, Object data) throws Exception { User person = (User) data; item.setValue(person); Listcell lc1; lc1 = new Listcell(String.valueOf(person.getiUserID())); lc1.setParent(item); Listcell lc3; lc3 = new Listcell(String.valueOf(person.getsDescription())); lc3.setParent(item); Listcell lc4; lc4 = new Listcell(String.valueOf(person.getsEmail())); lc4.setParent(item); Listcell lc5; lc5= new Listcell(String.valueOf(person.getsHashCode())); lc5.setParent(item); Listcell lc6; lc6 = new Listcell(String.valueOf(person.getsRole())); lc6.setParent(item); Listcell lc2; lc2 = new Listcell(String.valueOf(person.getsUserName())); lc2.setParent(item); }
Lc is listcell so the first I only have one listcell, I think in ZK build listcell must detemine listcell to put in to viewer
last question:
now I want to sort in listbox ? how can I do it ?
i see at http://books.zkoss.org/wiki/ZK_Component_Reference/Data/Listbox and apply to my template
but it have error :
org.zkoss.zk.ui.metainfo.PropertyNotFoundException: Method setSortDirection not found for class org.zkoss.zul.Listhead
org.zkoss.zk.ui.metainfo.PropertyNotFoundException: Method setSortDirection not found for class org.zkoss.zul.Listhead
org.zkoss.lang.SystemException: org.xml.sax.SAXParseException; systemId: file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/BaseWeb/pages/user/test.zul; lineNumber: 86; columnNumber: 50; Element type "listheader" must be followed by either attribute specifications, ">" or "/>".
Please help me !!!
At first you write not the STANDART way of naming your getters/setters in the domain class
person.getEmail and NOT person.getsEmail ;
please correct this in all of your domain classes to prevent failures by other frameworks/libs in your project that call these getters per reflection api.
The best way is to let Eclipse generate the getter/setter for your domian class properties self.
second the count of Listheaders should match the rendered ListCells
. . . // username lc = new Listcell( String.valueOf( person.getUserName() )): lc.setParent(item); // description lc = new Listcell( String.valueOf( person.getDescription() )): lc.setParent(item); // email lc = new Listcell( String.valueOf( person.getEmail() )): lc.setParent(item); . . .
best
Stephan
Asked: 2013-01-16 08:49:44 +0800
Seen: 89 times
Last updated: Jan 16 '13