Yep, so you could have something like:
private final String query = "select * from Foo"; // will be serialized as anon class var
IModel myModel = new AbstractDetachableModel()
{
private transient List list;protected void onAttach()
{
this.list = getMyList(query);
}protected void onDetach()
{
this.list = null;
}protected Object onGetObject(Component component)
{
return list;
}protected void onSetObject(Component component, Object object)
{
list = (List)object;
}public Object getNestedModel()
{
return null;
}
};I must admit that I'm using a custom base object for most of my models since last changes:
public abstract class DetachableModel extends AbstractDetachableModel
{
private transient Object tempModelObject;public DetachableModel()
{
super();
}protected void onDetach()
{
tempModelObject = null;
}protected final Object onGetObject(Component component)
{
return tempModelObject;
}protected final void setObject(Object object)
{
setObject(null, object);
}protected final void onSetObject(Component component, Object object)
{
this.tempModelObject = object;
}public final Object getNestedModel()
{
return null;
}
}so that I can easily create detachable models like:
public class DefinitionTypeListModel extends DetachableModel
{
private static DefinitionDAO definitionDAO = new DefinitionDAO();protected void onAttach()
{
List definitionTypes = definitionDAO.findDefinitionTypes();
this.setObject(definitionTypes);
}
}Eelco
Cameron Braid wrote:
The issue that I think will eventuate from this is perforamce related.
If I have a list of 40 items each using a detachable model (based on entity id). When the request comes back (after a post) there will need to be 40 individual selects to re-attach the listitem models.
This is because detachable models seem to be automatically re-attachd automatically at the start of the request - even if the model isn’t accessed.
Would it be possible to have a lazy detachable model, such that it is only re-attached if / when the model is actually accessed ?
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
