Hi Simon,
BTW, I got distracted by some work on MyFaces documentation, so
haven't made much progress on my implementation of a custom
ListDataModel class, but it looks like Mario is using exactly this
approach which is very encouraging.
I guess you meant Mike.
But no problem, as I also use a custom DataModel which
1) knows how many records it will (virtually) hold
2) but in reality it will hold only the number of records requested by
the dataTable
I'll summarize:
<h:dataTable id="itemlist" ..... rows="20" >
</h:dataTable>
<x:dataScroller
id="dataScroll"
for="itemlist"
fastStep="10"
pageCountVar="pageCount"
pageIndexVar="pageIndex"
styleClass="scroller"
paginator="true"
paginatorMaxPages="9"
paginatorTableClass="paginator"
paginatorActiveColumnStyle="font-weight:bold;"
>
In the backend I have something like:
public DataModel createDataModel(final int startAt, final int
nuofRecords)
where startAt (table.getFirst()) and nuofRecord (table.getRows()) can be
taken from the dataTable.
Since this is a hibernate/criteriaApi solution I am able to execute ANY
query twice, once to determine the number of records, second to get
"nuofRecord" records starting at "startAt".
All in all it my DataModel is backed by a ListDataModel, but it always
only holds a list of nuofRecord.
Works like a charme, and bleedingly fast.
Should be no problem to implement this with plain sql too. As long as
your database supports "sub selects" - something like:
select count(*) from (select .......)
For the "startAt/nuof records" stuff your database should be able to
"limit/offset" a select, or in case of oracle you have to do some
"rownum" (hibernate Oracle9Dialect.getLimitString) tricks.
Oh boy, I talk too much, hope it was interesting anyway.
---
Mario