0

I did as the same demo but still now show data

asked 2013-01-16 08:49:44 +0800

zerocold gravatar image zerocold
128 1

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 :(

delete flag offensive retag edit

11 Answers

Sort by ยป oldest newest most voted
0

answered 2013-01-16 11:29:32 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2013-01-16 11:31:40 +0800

sort="auto(username)

Look at this thread

link publish delete flag offensive edit
0

answered 2013-01-16 10:47:25 +0800

zerocold gravatar image zerocold
128 1

i got error when I put sort="auto" at listheader is username:


mcrt.model.User cannot be cast to java.lang.Comparable

link publish delete flag offensive edit
0

answered 2013-01-16 10:29:20 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

. . .
<listhead>
	<listheader label="User Name" align="left"  sort="auto"/>
        . . .

best
Stephan

link publish delete flag offensive edit
0

answered 2013-01-16 10:08:42 +0800

zerocold gravatar image zerocold
128 1

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 !!!

link publish delete flag offensive edit
0

answered 2013-01-16 10:06:01 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

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(...

link publish delete flag offensive edit
0

answered 2013-01-16 09:59:18 +0800

zerocold gravatar image zerocold
128 1

@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

link publish delete flag offensive edit
0

answered 2013-01-16 09:57:07 +0800

zerocold gravatar image zerocold
128 1

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 !!!

link publish delete flag offensive edit
0

answered 2013-01-16 09:54:37 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2013-01-16 09:57:09 +0800

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

link publish delete flag offensive edit
0

answered 2013-01-16 09:50:04 +0800

zerocold gravatar image zerocold
128 1

oh I did it ;)

i'm so stupid. it only create some Listcell then i will show all table :)

thank you so much, mr: terrytornado

link publish delete flag offensive edit
0

answered 2013-01-16 09:35:52 +0800

zerocold gravatar image zerocold
128 1

i dont know what i must say to thanks you so much : terrytornado. I can do it , it run

but now when i fixed them , my table still show only 1 column :

please see it:

please help me

link publish delete flag offensive edit
Your answer
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: 2013-01-16 08:49:44 +0800

Seen: 89 times

Last updated: Jan 16 '13

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