ListView + dynamic database Model

2010-03-02 Thread marioosh.net
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
ListTab 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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: ListView + dynamic database Model

2010-03-02 Thread Thomas Kappler

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
ListTab  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 Kapplerthomas.kapp...@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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: ListView + dynamic database Model

2010-03-02 Thread marioosh.net



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
   ListTab  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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org