You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "marioosh.net" <ma...@gmail.com> on 2010/03/02 11:55:01 UTC
ListView + dynamic database Model
Sorry for my poor english ;)
I have ListView and model like below. I need tabs to reload sometimes,
so my model is dynamic and get tabs from database.
But i see that something is wrong. When i want to get Tab object by
getModelObject() in populateItem method i suppoused that i got it
directly, but i see that all the times the getObject() method of model
is triggered making for all items new list (new db request) !
How to get Tab objects for items without making wasting time database
request ???
IModel model = new IModel() {
public Object getObject() {
System.out.println("getObject...");
...
// getting list from DB
List<Tab> list = ....;
return list;
}
public void setObject(Object object) {}
public void detach() {
}};
ListView tabs = new ListView("tabs", model) {
@Override
protected void populateItem(ListItem item) {
item.getModelObject(); /* <------------- new list, and new list,
and new list...... :(
}
};
--
Greetings,
marioosh
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ListView + dynamic database Model
Posted by "marioosh.net" <ma...@gmail.com>.
Thomas Kappler-3 wrote:
>
> On 03/02/10 11:55, marioosh.net wrote:
>> Sorry for my poor english ;)
>>
>> I have ListView and model like below. I need tabs to reload sometimes,
>> so my model is dynamic and get tabs from database.
>> But i see that something is wrong. When i want to get Tab object by
>> getModelObject() in populateItem method i suppoused that i got it
>> directly, but i see that all the times the getObject() method of model
>> is triggered making for all items new list (new db request) !
>
> That's exactly what is supposed to happen, as getModelObject() is just a
> shorthand for getModel().getObject(). And in your getObject(), you do
> the database request.
>
> If you need to avoid those database reloads, look into
> LoadableDetachableModels.
>
> -- Thomas
>
Thank You very much Thomas.
I move code from getObject() method in IModel to load() method in
LoadableDetachableModel and everything works! - no more useless requests to
db :)
LoadableDetachableModel model2 = new LoadableDetachableModel() {
@Override
protected Object load() {
...
// getting list from DB
List<Tab> list = ....;
return list;
}
};
--
View this message in context: http://old.nabble.com/ListView-%2B-dynamic-database-Model-tp27754495p27754908.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: ListView + dynamic database Model
Posted by Thomas Kappler <th...@isb-sib.ch>.
On 03/02/10 11:55, marioosh.net wrote:
> Sorry for my poor english ;)
>
> I have ListView and model like below. I need tabs to reload sometimes,
> so my model is dynamic and get tabs from database.
> But i see that something is wrong. When i want to get Tab object by
> getModelObject() in populateItem method i suppoused that i got it
> directly, but i see that all the times the getObject() method of model
> is triggered making for all items new list (new db request) !
That's exactly what is supposed to happen, as getModelObject() is just a
shorthand for getModel().getObject(). And in your getObject(), you do
the database request.
If you need to avoid those database reloads, look into
LoadableDetachableModels.
-- Thomas
>
> How to get Tab objects for items without making wasting time database
> request ???
>
>
> IModel model = new IModel() {
> public Object getObject() {
> System.out.println("getObject...");
> ...
> // getting list from DB
> List<Tab> list = ....;
> return list;
> }
>
> public void setObject(Object object) {}
> public void detach() {
> }};
>
> ListView tabs = new ListView("tabs", model) {
> @Override
> protected void populateItem(ListItem item) {
> item.getModelObject(); /*<------------- new list, and new list,
> and new list...... :(
> }
> };
>
--
-------------------------------------------------------------------
Thomas Kappler thomas.kappler@isb-sib.ch
Swiss Institute of Bioinformatics Tel: +41 22 379 51 89
CMU, rue Michel Servet 1
1211 Geneve 4
Switzerland http://www.uniprot.org
-------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org