Hi,
I have done such a taglib for the company I am working for, but I can't give you the sources. However, I can provide some hints. Regarding the UI relates stuff, my taglib implementation is very simillar with the display tag or value list tag implementations; the main difference is how you specify the tabular data that needs to be displayed.
My taglib needs is some sort of tabular data source, like value list needs a ValueListAdapter or display tag needs a collection. For this I have a TableModel interface that looks something like this:
Code:
public interface TabelModel {
public int getRowCount();
public int getColumnCount();
public Object getCellValue(int row, int column);
}
There is also a SortableTableModel for tabular data that needs sorting by its columns:
Code:
public interface SortableTableModel extends TabelModel {
public void sort(int column, boolean ascending);
}
When displaying page x of data, the taglib will call TableModel.getCellValue() for each row bewteen x* pageSize and (x+1) * pageSize. When sorting by one of the columns, the SortableTableModel.sort() method will be called.
I have some support classes that take care of the pagination like this:
When first page is required, obtain the list of all the ids of the rows in the table:
Code:
select id from my_table where ... order by col1 asc
Keeping in memory lists having up to tens of thousands ids (Integer or Long objects) is not a big deal, and it should not cause any memory related problems. Having the list of all ids, you can also display the total number of rows.
Besides the list of all ids, it also keeps in memory a local cache for the current page of data being displayed. So, when the getCellValue() is called for the cell of the page, the local cahe is loaded by executing a query like:
Code:
select * from my_table where id in (id1, id2,id3 ....)
Then the rest of the cell values are retrieved from the cache. When dispalying another page, only the page data query is executed:
Code:
select * from my_table where id in ( ....)
The page data query is supposed to be faster, because you explicitely specify the ids of the rows you need. The cached list of all ids is refershed only when sorting by a column or explicitelly requesting a refresh. This suits very well for large datasets and for comoplex queries; you pay the cost of the query only at the initialization or sorting requests, when the ids query is excuted. In my opinion this works better that the solution mentioned on hibernate docs (http://blog.hibernate.org/cgi-bin/bl...hh/%5B/url%5D.) where you have to pay the cost of the query each time you browse back and forth through the pages of data.
This is just a specific implementation of the TableModel, targeted at browsing through large tabular data sets. Of course you can provide your own TableModel implementation that is more suitable in other cases.