You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@click.apache.org by Bob Schellink <sa...@gmail.com> on 2009/03/18 19:55:59 UTC
Promote Table getFirstRow and getLastRow to public
Its been suggested before to promote getFirstRow and getLastRow as
public methods. Any reasons we should not do this for 2.1.0?
This change makes it easier to enable paging of large datasets.
Currently a Table's rowList must contain entries (even if its just a
placeholder object) at every index in the list.
By having the two methods as public an adapter or proxy could be used
as the Table's rowList and it only need to be populated with the
entries that should be displayed. So if the pageSize is 10, the
rowList only needs 10 entries, for example:
public class TableModel extends ArrayList {
private Table table;
private int numOfRows;
public TableModel(Table table, int numOfRows) {
this.table = table;
this.numOfRows = numOfRows;
}
public Object get(final int index) {
// Convert expected index to real index
int realIndex = index - table.getFirstRow();
return super.get(realIndex);
}
public int size() {
// Return numOfRows e.g. 100, even if only 10 entries exist
return numOfRows;
}
}
TableModel example usage:
public void onRender() {
TableModel model = new TableModel(table, getCustomerCount());
table.setRowList(rows);
List customers = getCustomers(table.getFirstRow(),
table.getLastRow(), table.getPageSize());
model.addAll(customers);
}
regards
bob
Re: Promote Table getFirstRow and getLastRow to public
Posted by Malcolm Edgar <ma...@gmail.com>.
+1
On Thu, Mar 19, 2009 at 5:55 AM, Bob Schellink <sa...@gmail.com> wrote:
> Its been suggested before to promote getFirstRow and getLastRow as public
> methods. Any reasons we should not do this for 2.1.0?
>
> This change makes it easier to enable paging of large datasets. Currently a
> Table's rowList must contain entries (even if its just a placeholder object)
> at every index in the list.
>
> By having the two methods as public an adapter or proxy could be used as
> the Table's rowList and it only need to be populated with the entries that
> should be displayed. So if the pageSize is 10, the rowList only needs 10
> entries, for example:
>
>
> public class TableModel extends ArrayList {
> private Table table;
> private int numOfRows;
>
> public TableModel(Table table, int numOfRows) {
> this.table = table;
> this.numOfRows = numOfRows;
> }
>
> public Object get(final int index) {
> // Convert expected index to real index
> int realIndex = index - table.getFirstRow();
> return super.get(realIndex);
> }
>
> public int size() {
> // Return numOfRows e.g. 100, even if only 10 entries exist
> return numOfRows;
> }
> }
>
> TableModel example usage:
>
> public void onRender() {
> TableModel model = new TableModel(table, getCustomerCount());
>
> table.setRowList(rows);
>
> List customers = getCustomers(table.getFirstRow(), table.getLastRow(),
> table.getPageSize());
>
> model.addAll(customers);
> }
>
> regards
>
> bob
>