You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris <ch...@gmx.at> on 2015/02/14 22:23:22 UTC
ListPanel - update model
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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ListPanel - update model
Posted by Martin Grigorov <mg...@apache.org>.
On Sun, Feb 15, 2015 at 6:48 PM, Chris <ch...@gmx.at> 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 <
> francois.meillet@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 <ch...@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-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: ListPanel - update model
Posted by Chris <ch...@gmx.at>.
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 <fr...@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 <ch...@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-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ListPanel - update model
Posted by Francois Meillet <fr...@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 <ch...@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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
Re: ListPanel - update model
Posted by Martin Grigorov <mg...@apache.org>.
Hi,
On Feb 14, 2015 11:24 PM, "Chris" <ch...@gmx.at> wrote:
>
> 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());
^^^ Here you loose the connection to listPanel.
Instead do :
pModel.clear()
pModel.addAll(...)
> target.add(listPanel);
> }
> });
> }
>
> Thanks!
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>