2013-02-07 93 views
3

我遇到了顯示攜帶2750行的ArrayList的問題。這些支柱代碼顯示行:打破ArrayList並在Struts中顯示1

<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> 

這種情況的操作方法是:

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); 
} 

現在我需要可以打破ArrayList customerlist並傳送到JSP在五十塊,並顯示或顯示他們在JSP中,以便它在渲染時不會很慢。

回答

2

列表存儲2750條記錄不是建議的方式。從數據庫/存儲讀取數據時,請考慮它的含義,以及將數據傳遞到Web /應用程序服務器時的含義。你也可能不需要一口氣。

請考慮一次抓取並顯示100個數據塊的數據。您可以通過傳遞索引來始終向服務器發起新呼叫以獲取下一組記錄。

如果你還沒有使用靜態,你也必須使用Ajax;通過這種方式,您可以繼續將其餘數據附加到頁面而無需刷新。

+0

我已經開始使用jqGrid和jqueryUI主題來實現目的。 –

0

我會建議使用分頁機制,以便您可以在給定時間加載50或100條記錄。看看這個extremetable

0

Struts <logic:iterate>標籤有offsetlength屬性可以用來顯示集合的部分。下面將顯示ArrayList中的前50個元素。

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

在這種情況下,您是否必須將全部2750條記錄加載到內存中? – Suranga

+0

@guess_me是的,你將有數據庫發送你2750記錄,你轉換爲2750對象只能使用其中的50個。 – Esailija

+0

但是這隻會顯示50行,我需要顯示所有的數據,但一次呈現50。 –

0

您不應該將列表customerlist分解爲「以塊形式發送給jsp」。相反,您可以打破將返回給定數量記錄的方法,即customerManager.getCustomerForBeneficiaryWithCount(perPage);或使用JSP邏輯標記來限制使用兩個參數firstRowperPage的渲染行。