直接从JSF / richfaces访问基于java的DOM树 [英] Accessing java-based DOM tree directly from JSF/richfaces
问题描述
基于这个问题我有一个其他几个问题:
Based on this question I have a couple of other questions:
1)这个问题中可用于jsf的地图实际上是一个数字,所以我现在不确定是什么支持bean方法的返回类型现在应该是。如果我修改它的当前数组< String>
返回类型为数组< Map Integer,Map< String,String []>>>
(或 ArrayList< Map Integer,Map< String,String []>>>
?)它是否只是进一步嵌套的情况jsf端的迭代器?麻烦是一个Array / ArrayList不是Map,我不确定它在jsf中的表现如何。这是正确的:
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. 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? Trouble is an Array/ArrayList isn't a Map and I'm unsure how this then looks in 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)我是什么真正存储在这个映射中的是从java端解析的XML DOM树中的xpath rips。我现在想我可以直接从JSF访问这个基于java的DOM树而不必使用XPath - > ArrayOfMaps并返回它。在看起来像这样的XML文件中,有比使用上述方法更好的方法吗?:
2) what i'm really storing in this map is xpath rips from an XML DOM tree parsed on the java side. i'm now thinking i can access this java-based DOM tree from JSF directly without having to use XPath -> ArrayOfMaps and return that. In an XML file which looks something like this, is there a better way than using the above method?:
<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>
再次感谢
Mark
Thanks again Mark
推荐答案
<c:forEach items="#{bean.map}" var="entry"> <!-- array -->
<c:forEach items="#{entry.value}" var="nentry"> <!-- map -->
这是错误的。对于 ArrayList
的每次迭代都不会像您想象的那样返回 Map.Entry
对象。它只返回 List
的单个元素(在您的情况下为 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 -->
简而言之, a c:forEach
迭代列表
或对象[]
如下
In nutshell, a c:forEach
iteration over an List
or Object[]
as follows
<c:forEach items="${array}" var="item">
...
</c:forEach>
最好在原始Java代码中解释为
is best to be interpreted in raw Java code as
for (Object item : array) {
// ...
}
而 c:forEach
迭代超过地图
如图所示在上一主题中最好在原始Java代码中解释为:
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}
}
这篇关于直接从JSF / richfaces访问基于java的DOM树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!