开发者

JSP Struts reverse iterator

I got a jsp page where Struts iterator is used to fetch items from the db.

Is there some way reverse the order of the result set?

Note: I don't have the source code, hence can't do it via the class开发者_Go百科 and re-compile


The <logic:iterate> tag isn't very flexible in this regard. It is just an iterator exposed as a tag. So the only way to reverse the result set is to do it before reaching the tag (i.e. reverse the collection of results higher in the application layers (with something like this or similar) and use the <logic:iterate> tag on this (already) reversed collection).

If you need to reverse the collection in the JSP then maybe the JSTL <c:forEach> tag could work, something like:

<c:forEach items="${items}" begin="${fn:length(items) - 1}" end="0" step="-1">
  ....
</c:forEach>

If you don't like any of the above, then maybe you could write yourself whatever type of tag iterator you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜