-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm building a grid that takes the info from a database, but at the time of aquiring that info from the database, and turning it into an ArrayList, the grid in where each post should be ends up empty.
here is the zul:
<zk>
<borderlayout id="main" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('pojos.PostController')">
<!-- ... -->
<center style="padding:15px;" border="none">
<window onCreate="@command('getPosts')">
<window border="normal">
<grid height="550px" model="@command('vm.getPosts')" emptyMessage="Nothing in Posts.">
<template name="model">
<row>
<window border="normal">
<caption id="userName" label="@load(each.user)"/>
<textbox id="infoPost" readonly="true" value="@load(each.info)" multiline="true" rows="4" width="100%" mold="rounded"/>
<separator bar="true"/>
<hlayout>
<div>
<button label="Like" onClick="@command('addLike', index=each.index)"/>
</div>
<div hflex="true">
<textbox id="likeTB" disabled="true" width="3%" style="text-align:center" value="@load(each.likes)"/>
</div>
<div style="padding-right">
</div>
</hlayout></window></row></template></grid></window></center><!--...--></borderlayout>
</zk>
the <!--...-->
is just me skipping code that doesnt affect that section.
here is the PostController.java
@Command("getPosts")
@NotifyChange("*")
public List<Post> getPosts() throws Exception {
/*
org.hibernate.Transaction tx = session.beginTransaction();
List<Post> posts = new ArrayList(session.createSQLQuery("SELECT * FROM post").list());
System.out.println("ASSASSASS");
if (posts.size() > 0) {
return posts;
}*/
List<Post> test = new ArrayList<Post>();
test.add(new Post(1,"Username","Post Info",0));
return test;
}
I'm using Hibernate to obtain the posts from a PostgreSQL database, but after noticing that it failed, i commented that and just made a quick test. The page still shows a "Nothing in posts" where the grid should be instead of a list of posts.
this line doesn't seem right:
<grid height="550px" model="@command('vm.getPosts')" emptyMessage="Nothing in Posts.">
most likely you wanted to do this:
model="@init(vm.posts)"
or (in case you really want trigger the load binding after a command, then don't use a getter as the command name ... that's just weird and unexpected)
model="@load(vm.posts, after='loadPosts')
Asked: 2019-04-11 06:58:04 +0800
Seen: 5 times
Last updated: Apr 11 '19