0

BUG: MVVM Bind calls getter multiple times [closed]

asked 2014-09-11 11:22:19 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

updated 2014-09-11 15:14:53 +0800

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

delete flag offensive retag edit

The question has been closed for the following reason "duplicate question" by cyiannoulis
close date 2014-09-25 13:11:35

Comments

i had the same bug

pomidor ( 2014-09-11 12:03:35 +0800 )edit

Did 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 )edit

I can't reproduce this issue. Please refer to the zkfiddle sample I created.

vincentjian ( 2014-09-18 09:53:53 +0800 )edit

Vincent, 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 )edit

Vincent 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

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-09-13 15:12:49 +0800

Darksu gravatar image Darksu
1991 1 4

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

link publish delete flag offensive edit
0

answered 2014-09-13 19:02:08 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2014-09-13 19:03:46 +0800

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

link publish delete flag offensive edit
0

answered 2014-09-15 07:58:59 +0800

cyiannoulis gravatar image cyiannoulis
1201 10

@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

link publish delete flag offensive edit

Question tools

Follow
1 follower

RSS

Stats

Asked: 2014-09-11 11:22:19 +0800

Seen: 32 times

Last updated: Sep 15 '14

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