1

Current Problem: We are currently trying to fetch over 500k (Five hundred thousand) records from the database and then I have to show 50 records per page on a JSP (using struts 2). Problem is it takes time loading long time or even some time it does not. Once it is loaded we are able to navigate smoothly.

Solution Needed: Like to load limited records as per the pagination defined records, for eg: each page upto 100 records.Has anyone implemented similar functionality in struts or similar framework? also i dont want to get all records at once. please guide me how to implement?

Santosh
  • 11
  • 1
  • 3
  • 2
    For pagination of the SQL query, see: http://stackoverflow.com/questions/1986998/resultset-to-pagination For displaying paginated results using Struts2, see: http://stackoverflow.com/questions/777199/pagination-through-struts2-using-displaytag-library-framework – Philipp Reichart Apr 25 '12 at 12:13
  • possible duplicate of [how can i using paging with struts 2 and hibernate](http://stackoverflow.com/questions/18961314/how-can-i-using-paging-with-struts-2-and-hibernate) – Roman C Jan 28 '14 at 10:26

2 Answers2

0

You can fetch only 100 records at each request based on some parameter.Fetching all records in one go will take long time .I had implemented pagination using query and some parameter.

amicngh
  • 7,831
  • 3
  • 35
  • 54
0

You can use jquery datatable. which has pagination functionality for ajax load. so when you click on next page it loads next records from database. For this you need to add Jquery library like jquery.dataTables.min.js,jquery-ui-1.8.10.custom.min.js , jquery-1.4.4.min.js, jquery-1.4.2.min.js, jquery-ui-1.8.10.custom.css

JSP code

<table id="reqAllQueriesTable" cellpadding="0" cellspacing="0" border="0" class="display" style="width: 100%;">
    <thead>
    <tr>
    <th style="display: none"></th>
    <th>&nbsp;</th>
    <th><spring:message code='Name'/></th>
    <th><spring:message code='runDate'/></th>
    th><spring:message code='noOfRec'/></th>
    </tr>
    </thead>
    <tbody>
    </tbody>
</table>

JavaScript

var oTable = $('#reqAllQueriesTable')
                .dataTable(
                        {
                            "bProcessing": true,
                            "bServerSide": true,
                            "sAjaxSource": "query/getQuery",
                            "bPaginate" : true,
                            "bScrollCollapse" : true,
                            "iDisplayLength" : 10,
                            "bFilter" : true,
                            "bJQueryUI" : true,
                            "sPaginationType" : "full_numbers",
                            "oLanguage" : {
                                "sLengthMenu" : "Display _MENU_ records per page",
                                "sZeroRecords" : "No  Queries found",
                                "sInfo" : "Showing _START_ to _END_ of _TOTAL_ records",
                                "sInfoEmpty" : "Showing 0 to 0 of 0 records",
                                "sInfoFiltered" : "(filtered from _MAX_ total records)"
                            },
                            "aaSorting" : [ [ 3, "desc" ] ],
                            "aoColumns" : [/*Id*/{
                                "bSearchable" : false,
                                "bVisible" : false
                            },
                            /*Id RadioButton*/{
                                "bSearchable" : false,
                                "bSortable" : false
                            },
                            /*Name*/null,
                            /*Run Date*/{
                                "sType" : "date"
                            },                          
                            {
                                "fnRender" : function(oObj) {

                                return '<input type="radio"  name="Id" value= "' + oObj.aData[0] + " "/>';
                                },
                                "aTargets" : [ 1 ]
                            }]
                        });
xrcwrn
  • 5,339
  • 17
  • 68
  • 129
Raje
  • 3,285
  • 15
  • 50
  • 70