Uh, forget the List constructor... the list should know how to load
itself, e.g. by using a delegate/ strategy.
Eelco
Eelco Hillenius wrote:
We're in the process of reconsidering the ListView implementation
alltogether I think.
If you really want this, you could provide a custom list that does
this. That list could lazily load it's size: when not set yet, you
load the actual list (e.g. from a database), but when set, return it.
And then the actual loading should occur when one of it's accessor
methods (like get(int) is called.
E.g (haven't tested it, but the idea should work):
public class LazyList extends ArrayList
{
private int size = -1;
private boolean loaded = false;
public LazyList(List list)
{
addAll(list);
}
public int size()
{
if(size == -1)
{
load();
this.size = super.size();
}
}
public get(int index)
{
load();
return super.get(index);
}
public void unload()
{
this.loaded = false;
}
private void load()
{
if(!loaded)
{
this.loaded = true;
// do loading here and call super.addAll(..)
}
}
.... etc ....
}
and your model is like:
public class MyModel extends AbstractDetachableModel
private LazyList myList; // keep reference to list allways; it'll
usually be empty
protected void onAttach()
{
if(myList == null)
{
myList = new LazyList(getSomeList());
}
}
protected void onDetach()
{
myList.unload();
}
protected Object onGetObject(Component component)
{
return myList;
}
.... etc ....
Btw, this might be a usefull pattern to either put on the Wiki or in
contrib. It's far more efficient for those cases where you have a list
that doesn't change over requests, are that you want to 'push' the
changes in, together with a ListView that doesn't remove it's items on
each request.
Eelco
It just happens that in my case - using a ListView - the list view calls
getModelObject within the onRender method (via getViewSize) this is
causing
my detached model to re-attach for every request - even repeated
IredirectListener requests.
Could this component possibly be changed to remember the size of the
list ?
Cameron
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Wicket-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-develop