Problem with pagination

I am facing a problem with pagination.
I have a group of record [company names] think as 100.
All this names are present in an vector.I am able to reterive the data & also display, but I need to display as 10 records in each page. If I click on next(url or button) it should display next 10 records of that particular column & vice-versa for pervious (url or button). Remember friends I am using postgres database.
 

Collections can help you a lot in this case...... here is

a skleton code which you can use to built yours.......

getRec(Iterator itr) {
    int maxRecords = 10;
    for(int i = 0; i < maxRecords && itr.hasNext(); i++) {
        // Get objects from the iterator...
    }

or else you can also use a procedure to which gets 10 recs at a time.
=============
bharath chinnadurai
scjp 1.4
 

I am not sure but why dont you try using the
setFetchSize() method.

This will give a hint to the JDBC driver as to how many records to fectch.

If you need to display 10 records then you may use
rs.setFetchSize(10)...where rs is the ResultSet variable.

However, this does not seem to be the best way since its only a hint to the JDBC driver as to how many rows
to fetch.

Tips by :Vinay

Pagination like Google

How do I do paging in my jsp page as similar as Google does?  I have 300 records to display. and i want to show 10 records per page.  I would like to implement pagination as similar as Google.

There are examples in the distribution bundle but basically it's like this.

Suppose you've got 1000 records in a requestScope list or map called data:

<display:table name="data" scope="request" id="record">
     <display:column title="Title 1" property="property1"/>
</display:table>

and so on... There's a manual also. And you can provide the size of the page, the styles, an url to lin on each column. You can render a column by yourself or make it to autolink if the column is an url or emailaddress...

Check the examples, they tell you how to do the whole thing. Also I'll cut'n' paste here a real code of my own for you to see. It's embeded in a struts based application. See the pagesize and requestURI wich will help you do the paging. The requestURI should store the data in an attribute called "listaContactos" in scope session. I just store the data when a search is requested, the pagination is done by the displaytag so if the user don't changes the search criteria the list is the same as in the previous page but just shows up the next 10 records.... emmmh... hope to have explained, sorry my bad english:

<<

                     <display:table sort="list" name="listaContactos"
scope="session" id="contacto"
requestURI="/secret/gestion/buscarContactos/view.do" pagesize="10"
align="center" width="400px">
                         <display:setProperty name="basic.msg.empty_list">
                             <p align="center">
                                 No hay resultados para la búsqueda.
                             </p>
                         </display:setProperty>
                         <display:column title="Nombre"
                                         sortable="true"

url="/secret/gestion/editarContacto.do?accion=editar"
                                         paramId="key"
                                         paramProperty="contactoId">
                                         <bean:write name="contacto"
property="apellido1"/>&nbsp;<bean:write name="contacto"
property="apellido2"/>, <bean:write name="contacto"
property="nombre"/>
                         </display:column>
                         <logic:match name="buscarContactosForm"
property="contactoEmpresa" value="true">
                             <display:column title="Cargo"
                                             property="cargo"
                                             sortable="true"

url="/secret/gestion/editarContacto.do?accion=editar"
                                             paramId="key"
                                             paramProperty="contactoId"
                                             group="15"/>
                             <display:column title="Empresa"
                                             property="nombreEmpresa"
                                             sortable="true"

url="/secret/gestion/editarEmpresa.do?accion=editar"
                                             paramId="key"
                                             paramProperty="empresaId"
                                             group="15"/>
                         </logic:match>
                         <display:column title="Tel&eacute;fono"
property="tlf1" width="60px"/>
                     </display:table>
 

>>

Tips by :Yayo

Related:

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.