Implement ListModel and TreeModel"

From Documentation
(Created page with "{{ZKDevelopersReferencePageHeader}} ''Under construction'' =Version History= {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content |- |   |   | ...")
 
m
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
''Under construction''
+
The default implementation of models, such as <javadoc>org.zkoss.zul.ListModelList</javadoc> and <javadoc>org.zkoss.zul.DefaultTreeModel</javadoc> assumes all data are available in the memory. It is not practical if a model has a lot of data. For huge data, it is suggested to implement your own model by loading and caching only a portion of data at a time.
 +
 
 +
To implement your own model, you could extend from <javadoc>org.zkoss.zul.AbstractListModel</javadoc>, <javadoc>org.zkoss.zul.AbstractGroupsModel<javadoc> and <javadoc>org.zkoss.zul.DefaultTreeModel</javadoc> as described in [[ZK Developer's Reference/MVC/Model|the Model section]]. To implement a model that supports sorting, you have to implement <javadoc type="interface">org.zkoss.zul.ListModelExt</javadoc> too. Each time an user requires sorting, <javadoc type="interface" method="sort(java.util.Comparator, boolean)">org.zkoss.zul.ListModelExt</javadoc> will be called and the implementation usually clears the cache and re-generate the SQL statement accordingly.
 +
 
 +
For a real example, please refer to [[Small Talks/2009/July/Handling huge data using ZK|Small Talk: Handling huge data using ZK]].
  
 
=Version History=
 
=Version History=

Revision as of 11:37, 9 March 2011


Implement ListModel and TreeModel


The default implementation of models, such as ListModelList and DefaultTreeModel assumes all data are available in the memory. It is not practical if a model has a lot of data. For huge data, it is suggested to implement your own model by loading and caching only a portion of data at a time.

To implement your own model, you could extend from AbstractListModel, AbstractGroupsModel and org.zkoss.zul.DefaultTreeModel as described in the Model section. To implement a model that supports sorting, you have to implement ListModelExt too. Each time an user requires sorting, ListModelExt.sort(Comparator, boolean) will be called and the implementation usually clears the cache and re-generate the SQL statement accordingly.

For a real example, please refer to Small Talk: Handling huge data using ZK.

Version History

Last Update : 2011/03/09


Version Date Content
     



Last Update : 2011/03/09

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.