Hi,

when using 

pModel = new ListModel<P>(){
   @Override
   public List<P> getObject() {
      return someService.calculate();
   }
};

I experience that in this case #someService.calculate() is called several times 
consecutively when loading the page. Why is this the case?

Setting the model in the Ajax Link onclick method as 
pModel.setObject(someService.calculate()); seems to work.

Chris


> Am 15.02.2015 um 10:40 schrieb Francois Meillet <francois.meil...@gmail.com>:
> 
> Hi Chris,
> 
> The ListModel keeps a reference on the model created at the first occurence 
> of that line
> pModel = new ListModel<P>(someService.caculate());
> 
> The simplest thing you could do is to reset the listpanel's model,
> but this is not a good practice.
> 
> listPanel.setDefaultModel(model);
> 
> add(new AjaxFallbackLink("link") { 
>            @Override 
>            public void onClick(AjaxRequestTarget target) { 
>                pModel = new ListModel<P>(someService.caculate()); 
>                listPanel.setDefaultModel(pModel);
>                target.add(listPanel); 
>            } 
>    }); 
> 
> 
> Using a specific model is much better
> For example, using the int property flag we can do 
> 
> pModel = new Model<String>() {
>       @Override
>       public String getObject() {
>               return "flag_" + flag ;
>       }
> };
> 
> final Panel listPanel = new ListPanel("itemList", pModel); 
> add(listPanel); 
> 
> add(new AjaxFallbackLink("link") { 
>            @Override 
>            public void onClick(AjaxRequestTarget target) { 
>                flag++;
>                target.add(listPanel); 
>            } 
>    }); 
> 
> 
> Have a look at https://wicket.apache.org/guide/guide/single.html#modelsforms
> 
> 
> François Meillet
> 
> 
> 
> 
> 
> Le 14 févr. 2015 à 22:23, Chris <chris...@gmx.at> a écrit :
> 
>> Hi all,
>> 
>> I would like to update a list model when the user clicks on a certain link. 
>> However, when the listPanel is rendered after clicking on the link, the 
>> model seems not to be updated and still contains the old values.
>> 
>> How to fix this?
>> 
>> PAGE:
>> 
>> IModel<List<P>> pModel;
>> 
>> public SomePage() {
>> 
>>      pModel = new ListModel<P>(someService.caculate());
>> 
>>      final Panel listPanel = new ListPanel("itemList", pModel);
>>      add(listPanel);
>> 
>>   add(new AjaxFallbackLink("link") {
>>           @Override
>>           public void onClick(AjaxRequestTarget target) {
>>               pModel = new ListModel<P>(someService.caculate());
>>               target.add(listPanel);
>>           }
>>   });
>> }
>> 
>> Thanks!
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to