0

Using JSF:

Is it possible to iterate over a Map whose values contain Maps?

I have a Map that looks like this:

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

I would like to iterate over myMap and display the result in a table.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

2 Answers2

0

Yes you can for sure, every map can be iterated getting the Entry Set, you will need to iterate in this case twice since you have a Map inside a Map...

Example:

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());
        }
    }
}
Community
  • 1
  • 1
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
0

JSF datatable component does not currently support iteration on a map (JSF 2.2). You will have to do a little work of transformation or use a c:forEach.

More on this here : Using java.util.Map in h:dataTable

Community
  • 1
  • 1
Dimpre Jean-Sébastien
  • 1,067
  • 1
  • 6
  • 14