0

Can not display data in listbox

asked 2014-05-23 10:47:31 +0800

Islem gravatar image Islem
3 1

updated 2014-05-23 10:51:26 +0800

Hi, I'm trying to create my first ZK app. I want to retrieve data from database and display them in my page. But, it's not working. The page shwo no data.

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>

<window title="Users Page" border="normal" apply="com.factory.UsersController">

<listbox id="box" multiple="true" rows="5" 
     model="@{win$composer.tousUsers, load-after='add.onClick, delete.onClick, update.onClick'}"
     selectedItem="@{win$composer.current}"
     >

    <listhead>            
        <listheader label="user_id" width="80px" />
        <listheader label="user_name" width="170px" />
    </listhead>       
    <listitem self="@{each='user'}" value="@{user}">            
       <listcell label="@{user.user_id}" />
        <listcell label="@{user.user_name}" />            
    </listitem>
</listbox>
<groupbox>
    <caption label="Event" />
ID: <intbox id="priority" cols="1" value="@{win$composer.current.user_id}" />
Name: <textbox id="name" cols="25" value="@{win$composer.current.user_name}"/>   

<button id="add" label="Add" />
<button id="update" label="Update" />
<button id="delete" label="Delete" />
</groupbox>

</window>

delete flag offensive retag edit

Comments

You can do 2 things, set some logging on the getters to see if they are called and if there info in it or create manually some data in your getters to see where your problem lies (zk or db). Greetz chill.

chillworld ( 2014-05-23 14:58:56 +0800 )edit

Thank you for your reply. I have testes my java classes and it work fine. I will do you sugegestion. But i think the proble is tke link between the controller and the page

Islem ( 2014-05-23 16:19:19 +0800 )edit

I have added some logging. After running the page, the log messages are not displayed. I think that the page does not call the controller

Islem ( 2014-05-23 16:42:50 +0800 )edit

can you post your composer?

chillworld ( 2014-05-23 21:36:34 +0800 )edit

6 Answers

Sort by ยป oldest newest most voted
0

answered 2014-05-24 01:20:03 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

Hello Islem, take a look at this link: Databind-example you can execute the code online, is very good for learning. On demo there are a goods examples with java class and zul, look the links below:

getting_started/mvc

getting_started/mvvm

link publish delete flag offensive edit
0

answered 2014-05-26 08:56:13 +0800

cor3000 gravatar image cor3000
4406 2 7
ZK Team

updated 2014-05-26 08:57:02 +0800

Hi Islem,

to avoid confusion: I seems you found an old example using the now (ZK7) deprecated DataBinding API (with org.zkoss.zkplus.databind.AnnotateDataBinderInit).

So if this is your first ZK application I suggest you start with either MVC or MVVM using the new ZK Bind.

In addition to the links given by mhj, please also follow the "ZK Essentials" tutorial.

Robert

link publish delete flag offensive edit
0

answered 2014-05-26 12:17:57 +0800

Islem gravatar image Islem
3 1

Hi mhj,

thank you for you apply. I have reviewed you link and correct some error in my code. But the data still not shown.

link publish delete flag offensive edit
0

answered 2014-05-26 12:18:45 +0800

Islem gravatar image Islem
3 1
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>

<zk>

<window id="win" title="Databind example"
        apply="com.factory.UsersComposer"
        >

    <listbox id="theList" multiple="true" rows="5"
        model="@{ListOfUsers}"
        selectedItem="@{selectedUser}">
        <listhead>
            <listheader label="ID" width="80px" sort="auto" />
            <listheader label="User" width="170px"  sort="auto" />
        </listhead>
        <listitem self="@{each=user}">
            <listcell value="@{user.user_id}" />
            <listcell value="@{user.user_name}"/>
        </listitem>
    </listbox>



</window>

</zk>

link publish delete flag offensive edit
0

answered 2014-05-26 12:19:09 +0800

Islem gravatar image Islem
3 1
package com.factory;

import java.util.List; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger;

import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Label; import org.zkoss.zul.ListModelList; import org.zkoss.zul.Listbox;

public class UsersComposer extends GenericForwardComposer {

/**
 * @param args
 */
 static final long serialVersionUID = -9145887024839938515L;
 UserDAO UserDAO = new UserDAO();
 Users current = new Users();
 Listbox box;
 List <Users> ListOfUsers;
 protected static Logger logger=
        Logger.getLogger("com.factory.UsersController");
//

 public void doAfterCompose(Component comp) throws Exception {
    super.doAfterCompose(comp);

    List<Users> ListUsers = getAllUsers();
    self.setAttribute("persons", ListUsers);
}


// Note: Something is omitted at here. You can view detail about this class on source code.

public List<Users> getAllUsers() {      
    return UserDAO.findAll();        
}



public void onClick$add() {
    // insert into database
    Users newUser = new Users(UUID.randomUUID().toString(), current.getUser_id(),current.getUser_name());
    logger.log(Level.WARNING, "getUser_id"+current.getUser_id());
    logger.log(Level.WARNING, "getUser_name"+current.getUser_name());
    UserDAO.insert(newUser);    
}

public void onClick$update() {
    if (box.getSelectedItem() != null) {
        // update database
        UserDAO.update((Users) box.getSelectedItem().getValue());
    }
}

public void onClick$delete() {
    if (box.getSelectedItem() != null) {
        UserDAO.delete((Users) box.getSelectedItem().getValue());
    }
}

public Users getCurrent() {
    return current;
}

public void setCurrent(Users current) {
    this.current = current;
}

private Users getSelectedUser() {
    ListModelList listModel = (ListModelList) box.getModel();
    Users selectedUser = (Users) listModel.getElementAt(box.getSelectedIndex());
    return selectedUser;
}



public static void main(String[] args) {
    // TODO Auto-generated method stub
    Users u = new Users();
    UsersComposer uc = new UsersComposer();
    List<Users> l = uc.getAllUsers();

    for (int i = 0;i<l.size();i++){
         u = (Users) l.get(i);
        System.out.println("*****"+u.getUser_name());
    }


}

}

link publish delete flag offensive edit

Comments

what is your public static void main doing in your composer? If you need init you have to override the public void doAfterCompose(T comp)

chillworld ( 2014-05-26 12:31:27 +0800 )edit
0

answered 2014-05-26 12:34:15 +0800

Islem gravatar image Islem
3 1

Hi All,

thank you for your support. I have fixed the issue.

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
3 followers

RSS

Stats

Asked: 2014-05-23 10:47:31 +0800

Seen: 47 times

Last updated: May 26 '14

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