0

Inconsistent Behavior with afterCompose + template in zul + data binding

asked 2010-02-09 11:43:07 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

updated 2010-02-09 11:44:30 +0800

Hello all,

This thread is about an inconsistence of behavior when using the same code in doAfterCompose() and on any event - like onClick. It's not a problem without "solution", but it's a problem to find out when it's causing "bugs".

I want to show a grid and have this grid populated when the page opens. This is the grid's code:

<button id="btnLoadData" label="Load data"/>
<grid id="grid">
    <columns>
        <column label="Foo"/>
        <column label="Bar"/>
    </columns>
    <rows>
        <row self="@{each=obj}" value="@{obj}">
            <label value="@{obj.foo}"/>
            <label value="@{obj.bar}"/>
        </row>
    </rows>
</grid>

On the composer I'll load the data:

public void loadGridData() {
    List<MyObj> objList = myService.getAllObjs();
    grid.setModel(new ListModelList(objList));
}

public void onClick$btnLoadData(){
    loadGridData();
}

This code works as expected. But what if I want to load the grid without clicking the button, the first idea is to use doAfterCompose method, so lets create it:

public void doAfterCompose(Component comp) {
    super.doAfterCompose(comp);
    loadGridData();
}

Now, when the page is loaded the grid shows a list of obj.toString(), ignoring the template configured in the zul page. Zk apparently changes the template to something like this:

<!-- other tags aren't changed -->
<row self="@{each=obj}">
    <label value="@{obj}"/>
</row>

This it the inconsistence behavior: setModel works as expected when called from events, but it mess up the template when called from doAfterCompose. Is this a design decision? I think it should be "fixed", what do you think?

P.S.: If you need more explanation on this, please let me know. I try to keep this first as small as possible.

P.S 2: I'm using ZK 3.6.3

Regards,

delete flag offensive retag edit

4 Replies

Sort by ยป oldest newest

answered 2010-02-11 03:29:47 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Hi,
It is the timing issue.
DataBinder was created and loadAll in Initiator's doAfterCompose which is run later than the Composer's doAfaterCompose.
In your case, you can use the following example to let Databinder handle the model setup.

<grid model="@{myService.allObjes}">

link publish delete flag offensive edit

answered 2010-02-17 13:38:43 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

Hi jumperchen,

But why setModel doesn't work in afterComposer and works everywhere else?

link publish delete flag offensive edit

answered 2010-02-19 13:47:50 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

Seems to me that when setModel is called from afterCompose the "live" template defined in the zul file is ignored/overriden and any moment later afterCompose setModel method doesn't overwrite the template.

link publish delete flag offensive edit

answered 2013-04-02 04:54:08 +0800

danielromero gravatar image danielromero
6

Hi, I detected the same behaviour in my code. Do you find any solution for that? that is, there are any way to catch the event that modifies some template?

link publish delete flag offensive edit
Your reply
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: 2010-02-09 11:43:07 +0800

Seen: 377 times

Last updated: Apr 02 '13

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