JSF how to iterate over map using ui:repeat

2011/07/07 § 3 Comments

private Map<String, ArrayList<Person>> myMap = new TreeMap<String, ArrayList<Person>>();

This is how my map look like and i want to display both key and value pair on my html page. ui:repeat doesn’t handle the Sets or Maps by default so here is the work around how we can make it work.

Reguar getter seter Person Class

public class Person {
private String name = "";

private String gender = "";
private String address = "";

public Person(String name, String gender, String address) {
this.name = name;
this.gender = gender;
this.address = address;
}
..
..
}

Make a function that returns only the keys of map

private ArrayList<String> keys = new ArrayList<String>();
private void myKeys(){
for(String key: blocks.keySet()){
keys.add(key);
}
}

Call the Map on jsf page as follows,

<ui:repeat value="#{mapBean.keys}" var="key">
<ice:outputLabel value="#{key}"/>
<ui:repeat var="item" value="#{mapBean.myMap[key]}">
<ice:outputLabel value="#{item.name}"/>
<ice:outputLabel value="#{item.adress}"/>
</ui:repeat>
</ui:repeat>
About these ads

Tagged:

§ 3 Responses to JSF how to iterate over map using ui:repeat

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading JSF how to iterate over map using ui:repeat at Dinesh Simk.

meta

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: