2013-10-04 79 views
2

我在3字段以下顯示用戶標識,值& upadtetime,我想按UPDCET.TIME以desc順序進行排序。請建議如何做到這一點。JSTL foreach - 對特定字段進行排序

<c:forEach var="comment" items="${document['kcmeta/comment']}"> 

<g2:out value="${mm:MasterValue('datamodel_userInfo',comment.USER_ID)}"/> 

<c:out value="${comment.VALUE}" /> 

<span class="searhResultLightGrayText"><c:out value="${comment.UPDATE_DATE}" /></span>   
</c:forEach> 

回答

0

沒有辦法,你可以通過使用c:forEachJSTL標籤排序任何類型的集合,但是你可以用的Scriplets使用和Java代碼嵌入到你的JSP處理這個問題。

<% 
    Collections.sort(yourList, new Comparator<Document>() { 
     public int compare (Document d1, Document d2) { 
      return d1.getUpdateTime().compare(d2.getUpdateTime()); 
     } 
    }); 
%> 

,然後你就可以遍歷您的排序列表:

<c:forEach var="comment" items="<%=youList%>"> 
    ... 
</c:forEach> 
+0

這不是做到這一點的最好辦法。看到這裏的討論:https://stackoverflow.com/questions/6638550/how-can-i-sort-a-list-several-different-ways-in-a-jsp – GabiM

+0

@GabiM:同意,這不是最好的方式來處理它,但我只是暴露了另一種方式,並不一定是最好的方式。 – Eder

+0

當然,它完成了這項工作。我剛剛爲其他人發表評論,以瞭解有更好的選擇 – GabiM

相關問題