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)
-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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>
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:
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
<?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>
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());
}
}
}
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)
Asked: 2014-05-23 10:47:31 +0800
Seen: 56 times
Last updated: May 26 '14
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 )editThank 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 )editI 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 )editcan you post your composer?
chillworld ( 2014-05-23 21:36:34 +0800 )edit