Accessing java-based DOM tree directly from JSF/richfaces

天涯浪子 提交于 2019-11-29 11:12:25
BalusC
<c:forEach items="#{bean.map}" var="entry">                     <!-- array -->
  <c:forEach items="#{entry.value}" var="nentry">               <!-- map -->

This is wrong. Each iteration over an ArrayList doesn't return a Map.Entry object at all as you seem to think. It just returns the individual element of the List (which is in your case a Map). Here's how it should look like:

<c:forEach items="#{bean.list}" var="map">                        <!-- array -->
  <c:forEach items="#{map}" var="entry">                          <!-- map -->


In nutshell, a c:forEach iteration over an List or Object[] as follows

<c:forEach items="${array}" var="item">
    ...
</c:forEach>

is best to be interpreted in raw Java code as

for (Object item : array) {
    // ...
}

while a c:forEach iteration over Map as demonstrated in your previous topic is best to be interpreted in raw Java code as:

for (Entry<K, V> entry : map.entrySet()) {
    K key = entry.getKey();       // ${entry.key}
    V value = entry.getValue();   // ${entry.value}
}

This article show a way to use recursion with JSTL. You can give it a try:

<c:forEach var="node" items="${node.children}">
    <c:set var="node" value="${node}" scope="request"/>
    <jsp:include page="node.jsp"/>
</c:forEach>

Just, in order to accommodate your case, you can put the following before the loop:

<c:set var="node" value="#{backingBean.rootNode}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!