Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
585 views
in Technique[技术] by (71.8m points)

jsp - 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. 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) 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:mypath</src>               
   <mask>.*.w{3}</mask>      
   <mask>.*.x</mask>          
  </inst>

  <inst>                                      
   <id>2</id>                  
   <src>C:myotherpath</src>               
   <mask>.*.w{3}</mask>      
   <mask>.*.x</mask>          
  </inst>
</test>

Thanks again Mark

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
<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}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...