[英]Accessing java-based DOM tree directly from JSF/richfaces
Based on this question I have a couple of other questions: 基于这个问题,我还有其他一些问题:
1) the map in this question which is made available to jsf is actually one of a number, so i'm now not sure what the backing bean method's return type should now be. 1)这个问题中可用于jsf的地图实际上是一个数字,所以我现在不确定支持bean方法的返回类型现在应该是什么。 if i modify it's current
Array<String>
return type to Array<Map Integer, Map<String, String[]>>>
(or ArrayList<Map Integer, Map<String, String[]>>>
?) would it just be a case of further nesting the iterator on the jsf side? 如果我修改它的当前
Array<String>
返回类型为Array<Map Integer, Map<String, String[]>>>
(或ArrayList<Map Integer, Map<String, String[]>>>
?)它只是在jsf端进一步嵌套迭代器的情况? Trouble is an Array/ArrayList isn't a Map and I'm unsure how this then looks in jsf. 麻烦是一个Array / ArrayList不是Map,我不确定它在jsf中的表现如何。 would this be correct:
这是正确的:
<c:forEach items="#{bean.map}" var="entry"> <!-- array -->
<c:forEach items="#{entry.value}" var="nentry"> <!-- map -->
<h:outputText value="Key: #{nentry.key}, Values:" /> <!-- integer -->
<c:forEach items="#{nentry.value}" var="nnentry"> <!-- sub map -->
<h:outputText value="Key: #{nnentry.key}, Values:" /> <!-- string -->
<c:forEach items="#{nnentry.value}" var="nnnentry"> <!-- string[] -->
<h:outputText value="#{nnnentry}" />
</c:forEach><br />
</c:forEach><br />
</c:forEach><br />
</c:forEach>
? ?
2) what i'm really storing in this map is xpath rips from an XML DOM tree parsed on the java side. 2)我真正存储在这个地图中的是从java端解析的XML DOM树中的xpath rips。 i'm now thinking i can access this java-based DOM tree from JSF directly without having to use XPath -> ArrayOfMaps and return that.
我现在想我可以直接从JSF访问这个基于java的DOM树而不必使用XPath - > ArrayOfMaps并返回它。 In an XML file which looks something like this, is there a better way than using the above method?:
在看起来像这样的XML文件中,有比使用上述方法更好的方法吗?:
<test>
<testid>1</testid>
<testname>myName</testname>
<inst>
<id>1</id>
<src>C:\my\path</src>
<mask>.*\.\w{3}</mask>
<mask>.*\.x</mask>
</inst>
<inst>
<id>2</id>
<src>C:\my\otherpath</src>
<mask>.*\.\w{3}</mask>
<mask>.*\.x</mask>
</inst>
</test>
Thanks again Mark 再次感谢马克
<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. 对于
ArrayList
每次迭代都不会像您想象的那样返回Map.Entry
对象。 It just returns the individual element of the List
(which is in your case a Map
). 它只返回
List
的单个元素(在您的情况下是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 简而言之,对
List
或Object[]
进行c:forEach
迭代,如下所示
<c:forEach items="${array}" var="item">
...
</c:forEach>
is best to be interpreted in raw Java code as 最好在原始Java代码中解释为
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: 而
c:forEach
遍历所有Map
为展示你在以前的题目最好是在原始的Java代码来解释:
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. 本文展示了一种使用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}" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.