Question

I'm stuck with a problem of displaying an ArrayList that carries 2750 rows. The struts code to display row is :

<c:forEach items="${customerlist}" var="beneficiaryListval"varStatus="ForIndex" >
<tr id="<c:out value="${beneficiaryListval.customerId}" />">
  <td><c:out value="${beneficiaryListval.fullName}" /></td>
    <td><c:out value="${beneficiaryListval.mobileNo}" /></td>
<td><c:out value="${beneficiaryListval.passportNo}" /></td>
    <td><c:out value="${beneficiaryListval.beneficiaryCount}" /></td>
</tr>
<%rowID++;%>
</c:forEach>

The action method for this is :

public ActionForward load(ActionMapping actionMapping,ActionForm     actionForm,HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) {
try {
mtmrsLogger.entering("BeneficiaryAction", "load");
BeneficiaryForm beneficiaryForm = (BeneficiaryForm) actionForm;
ArrayList customerlist = customerManager.getCustomerForBeneficiaryWithCount();
httpServletRequest.setAttribute("customerlist", customerlist);
beneficiaryForm.setPageStatus("CustomerGrid");
return actionMapping.findForward(Constants.getInstance().SUCCESS);
}

Now i need to either break the ArrayList customerlist and send to the JSP in chunks of fifty and display OR display them in the JSP so that it is not very slow while rendering.

Was it helpful?

Solution

Storing 2750 records in a List is not a suggested way. Please consider its implication when you reading it from DB/storage and also when you passing it around on your web/app server. Also you might not need all of them in one go.

Please consider fetching and displaying data in chunks like 100 at one time. You can always make a new call to server to get next set of records by passing index.

Also you will have to use Ajax if you are not using still; this way you can keep appending the remaining data to the page without refreshing.

OTHER TIPS

I would suggest to use pagination mechanism so that You will load 50 or 100 records at a given time. have a look on this extremetable

The Struts <logic:iterate> tag has offset and length attributes which can be used to display sections of a collection. The below would display the first 50 elements in the ArrayList.

<logic:iterate name="customerlist" id="customer" indexId="customerNum" offset="0" length="50">
    <tr id="${customer.customerId}">
        <td>${customer.fullName}</td>
        ...
    </tr>
</logic:iterate>

You shouldn't break the list customerlist to "send to the jsp in chunks". Instead you can break the method that will return a given number of records, i.e. customerManager.getCustomerForBeneficiaryWithCount(perPage); or use JSP logic tags to limit rendering rows using two parameters firstRow and perPage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top