Using JSF:
Is it possible to iterate over a Map
whose values contain Map
s?
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.
Using JSF:
Is it possible to iterate over a Map
whose values contain Map
s?
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...
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());
}
}
}
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