How to display the result of a map & lt; String, Map & lt; String, String & gt; & gt; on a datatable in JSF?

advertisements

This question already has an answer here:

  • Using java.util.Map in h:dataTable 3 answers

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.


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());
        }
    }
}