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 <[email protected]> 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: [email protected]
> For additional commands, e-mail: [email protected]
> 

Reply via email to