直接从JSF/richfaces访问基于java的DOM树。

时间:2022-09-25 12:23:49

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. 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:

1)这个问题中提供给jsf的映射实际上是一个数字,所以我现在不确定支持bean方法的返回类型应该是什么。如果我修改它的当前数组 返回类型为数组 >>(或ArrayList>>),会不会是在jsf端嵌套迭代器的情况?问题是数组/ArrayList不是映射,我不确定这在jsf中是什么样子。这是正确的:

<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. 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?:

2)在这个映射中,我真正要存储的是java端解析的XML DOM树的xpath片段。我现在想,我可以直接从JSF访问这个基于java的DOM树,而不必使用XPath -> ArrayOfMaps并返回它。在这样的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

再次感谢马克

2 个解决方案

#1


1  

<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:

这是错误的。在ArrayList上的每个迭代都不返回一个映射。进入对象,就像你认为的那样。它只返回列表的单个元素(在您的例子中是映射)。它应该是这样的:

<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 iteration over a List或Object[]如下所示

<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:对于前面主题中演示的Map上的每个迭代,最好在原始Java代码中解释为:

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

#2


0  

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

本文展示了使用JSTL使用递归的方法。你可以试试:

<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}" />

#1


1  

<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:

这是错误的。在ArrayList上的每个迭代都不返回一个映射。进入对象,就像你认为的那样。它只返回列表的单个元素(在您的例子中是映射)。它应该是这样的:

<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 iteration over a List或Object[]如下所示

<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:对于前面主题中演示的Map上的每个迭代,最好在原始Java代码中解释为:

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

#2


0  

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

本文展示了使用JSTL使用递归的方法。你可以试试:

<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}" />