-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi to all,
I am using zk 7.0.2 PE and 7.0.3 PE I have noticed that a getter in my view model is called multiple times causing me real trouble as this getter executes database transactions. The reason for this is that the control (in my case a selectbox) has been declared inside a Grid to make a nice form layout:
<row>Type
<selectbox model="@load(vm.questionnaires)" >
<template name="model" var="q" >
<label value="@load(q.name)" />
</template>
</selectbox>
</row>
In this case the getQuestionnaires() method is called four times during the page initialization. If i declare the <selectbox> outside the grid then it is called only once.
Posted as a bug (http://tracker.zkoss.org/browse/ZK-2444)
EDIT: I have just tried to remove the Grid and place all input controls inside a bootstraped form. Unfortunatelly the same thing happens. The getter is invoked mutliple times:
<n:form class="form-horizontal">
<n:div class="form-group">
<n:label class="col-sm-2 control-label">Questionnaire</n:label>
<div class="col-sm-4">
<selectbox model="@load(vm.questionnaires)">
<template name="model" var="q" >
<label value="@load(q.name)" />
</template>
</selectbox>
</div>
</n:div>
</n:form>
Costas
Hello cyiannoulis,
This is exactly what you have to do, in order to complete your task. In the @init phase load the data into an other object so that each iteration of the loop will target the new list.
Alternatively in my opinion you would have to create your grid depending more on java.
Best Regards,
Darksu
Hope i understand you right. The selectbox is in each rendered row of your grid. Not tested. Only an idea.
...
private int selectboxCounter = 0;
...
@init
public void init(){
...
}
@afterCompose
public void afterTheCompose(){
this.selectboxCounter = 1;
}
public model getSelectboxModel(){
if(this.selectboxCounter > 0){
return model;
} else {
return null;
}
}
best Stephan
@Stephan No, the selectbox is not declared inside a grid tempate. The grid is provided just to layout a nice looking input form with various input controls (like the zk demo). The problem is that the same happens even if i don't use a grid like this:
<n:form class="form-horizontal">
<n:div class="form-group">
<n:label class="col-sm-2 control-label">Questionnaire</n:label>
<div class="col-sm-4">
<selectbox model="@load(vm.questionnaires)">
<template name="model" var="q" >
<label value="@load(q.name)" />
</template>
</selectbox>
</div>
</n:div>
</n:form>
Anyway, to my opinion, this is a critical bug because it is not so obvious and may cause real problems after the application has gone into production.
Thanks guys for your answers
Asked: 2014-09-11 11:22:19 +0800
Seen: 32 times
Last updated: Sep 15 '14
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM
is there any event trigger from zk component on binding ?
ZK team plans to dispose of Composer EventQueues no longer in scope? [closed]
i had the same bug
pomidor ( 2014-09-11 12:03:35 +0800 )editDid you find any workaround (?) other than loading the data at the @init phase and then keep it as a field in your vm?
cyiannoulis ( 2014-09-12 09:35:55 +0800 )editI can't reproduce this issue. Please refer to the zkfiddle sample I created.
vincentjian ( 2014-09-18 09:53:53 +0800 )editVincent, it seems that it is more complicated than i thought. The problem appears when you are creating a new zul (Executions.createComponents) which is a child of another DIV from a previous hidden zul. I will try to make a sample.
cyiannoulis ( 2014-09-24 11:51:52 +0800 )editVincent i have updated the zkfiddle example. The problem is the sample runs with no problems on the zkfiddle web site. When i run it on our machines the problem persists(!) I have posted a new question here: http://forum.zkoss.org/question/94600/mvvm-bind-calls-getter-multiple-times/
cyiannoulis ( 2014-09-25 13:46:18 +0800 )edit