【问题标题】:How to display the result of a Map<String, Map<String, String>> on a datatable in JSF? [duplicate]如何在 JSF 中的数据表上显示 Map<String, Map<String, String>> 的结果? [复制]
【发布时间】:2016-10-17 00:54:47
【问题描述】:

使用 JSF:

是否可以遍历值包含Maps 的Map

我有一个看起来像这样的Map

Map<String, Map<String, String>> myMap;

我想遍历myMap 并将结果显示在表格中。

【问题讨论】:

    标签: jsf primefaces datatable hashmap


    【解决方案1】:

    JSF 数据表组件目前不支持在地图上进行迭代 (JSF 2.2)。 您将不得不做一些转换工作或使用 c:forEach。

    更多信息在这里:Using java.util.Map in h:dataTable

    【讨论】:

      【解决方案2】:

      是的,你可以肯定,每张地图都可以迭代获得Entry Set,在这种情况下你需要迭代两次,因为你的地图中有一个地图......

      示例:

      public static void main(String args[]) {
          Map< String, Map < String, String >> foo = new HashMap<String, Map < String, String >>();
          for (Entry<String, Map<String, String>> fooEntry : foo.entrySet()) {
              System.out.println(fooEntry.getKey());
              for (Entry<String, String> fooValueEntry : fooEntry.getValue().entrySet()) {
                  System.out.println(fooValueEntry.getKey());
                  System.out.println(fooValueEntry.getValue());
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多