-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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,
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}">
Hi jumperchen,
But why setModel doesn't work in afterComposer and works everywhere else?
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.
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?
Asked: 2010-02-09 11:43:07 +0800
Seen: 377 times
Last updated: Apr 02 '13