TaherT
TaherT

Reputation: 1335

Using rich datascroller With Hibernate Pagination on Server

I am having rich:datatable having 500(row) data and I am using rich:datascroller for pagination but the problem is all the data are fetched on 1st time, so if anybody having a way that click on page 2 hibernate fetches rows from table (11-20). I am using Spring+Hibernate. Please Give solution in detail.

Upvotes: 0

Views: 1537

Answers (2)

ikos23
ikos23

Reputation: 5354

You can make your own data scroller analogy with one task : to render via ajax the table U are using for records displaying !

e.g.

<rich:dataTable id="dtId" rows="10" value="#{bean.records}" var="record">
       // content (records)
</rich:dataTable>

your own scroller:

   <a4j:repeat value="#{bean.pages}" var="page">
     <a4j:commandLink value="#{page}" render="dtId" 
           actionListener="#{bean.myListener()}">
        <f:param name="selectedPageNumber" value="#{page}" />
     </a4j:commandLink>
     </a4j:repeat>

you will get a table and smth. like that after: 0 1 2 3 4 5 (#{bean.pages} - just numbers - means pages) and with click on each link (0123...) your listener (myListener) can retrieve new portion of data from DB and update #{bean.records} list and after rerendering you will have a table with new data !

Upvotes: 0

Bozho
Bozho

Reputation: 597144

You'd need a custom data model and a custom data provider. The Data provider will take care of fetching limited results, using query.setMaxResults(..). Note that since you are using spring, it would be good if your DataProvider instance is spring-managed.

Here is some code that we used for that purpose.

Upvotes: 1

Related Questions