0

Problem with grid model

asked 2019-04-11 06:58:04 +0800

FrankV427 gravatar image FrankV427
5 2

updated 2019-04-11 07:07:51 +0800

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.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-04-11 11:56:57 +0800

cor3000 gravatar image cor3000
4466 2 7
ZK Team

updated 2019-04-11 12:01:36 +0800

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')
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
1 follower

RSS

Stats

Asked: 2019-04-11 06:58:04 +0800

Seen: 5 times

Last updated: Apr 11

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