在JSTL中是否可以使用集合过滤器函数(更高阶函数)来返回新集合?

时间:2013-12-12 21:02:27

标签: java jsp collections filter jstl

我有一个集合,有两种类型Child_A和Child_B,它们扩展了一个Parent类。 有没有办法使用JSTL来使用过滤器函数来获取新的集合?即

List<Parent> myList --filter (element.getClass() == 'Child_A')
    --> List<Parent> myListOfChild_A
List<Parent> myList --filter (element.getClass() == 'Child_B')
    --> List<Parent> myListOfChild_B

这样我可以遍历子列表并对它们使用适当的测试。

目前,我只是使用测试,我在进行类型检查时迭代整个列表并且它没有给我我想要的功能,即

<c:forEach var="item" items="${myList}">
    <c:set var="item" value="${item}" scope="request"/>
    <c:if test="${item.getClass().simpleName == 'Child_A'}">
        <jsp:include page="child_A.jsp"/>
    </c:if> 
</c:forEach>
<%--I can't tell if there are any Child_A objects in my collection beforehand--%>

编辑:对不起,我忘了提到这是一个递归结构,其中每个Child_A对象都有一个Parent列表。

0 个答案:

没有答案
相关问题