On Sun, Feb 15, 2015 at 6:48 PM, Chris <[email protected]> wrote: > 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? >
See LoadableDetachableModel > > 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 < > [email protected]>: > > > > 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] > >> > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
