How to iterate over a TreeMap in Struts2

时间:2017-08-04 12:23:12

标签: java struts2

I have written the following Java code:

public Map<Integer, List<String>> createExampleMap(){

   Map<Integer, List<String>> myMap = new HashMap<Integer, List<String>>();

   List<String> liste1 = new ArrayList<String>();
   liste1.add("Failure55");
   liste1.add("Failure35");
   liste1.add("Failure15");

   List<String> liste2 = new ArrayList<String>();
   liste2.add("Failure10");
   liste2.add("Failure11");
   liste2.add("Failure12");

   List<String> liste3 = new ArrayList<String>();
   liste3.add("Failure99");
   liste3.add("Failure98");
   liste3.add("Failure97");

   myMap.put(10, liste1);
   myMap.put(2, liste2);
   myMap.put(5, liste3);

   return Map<Integer, List<String>> failureList = new TreeMap<Integer, String>(myMap);
)

Now I need a soultion to iterate over this TreeMap by using Struts2 Framework. Here I have written the following code:

<s:iterator value="failureMap" status="itFailureMap">

   <span>
       //Should be print out 10, 2 or 5
       <s:property value="failureMap[#itFailureMap].key"/> 
   </span>                      
   <s:iterator value="failureMap[#itFailureMap.index]" status="itFailureMapDetail" var="textLists">
      <ul>
          // Should be print out Failure99, Failure98 or Failure97 
          <li><s:property value="textLists[#itFailureMapDetail.index]"/></li>                   
      </ul>
   </s:iterator>
</s:iterator>   

But my code doesn´t work und I get no texts. No Error message was created. I get no for the keys und no output for the values (the String Lists). Could somebody explain to me, how I can iterate over a TreeMap by using Struts2?

0 个答案:

没有答案