You can use RichFaces to do such thing:
<h:form>
<rich:dataList var="city" value="#{myBean.allCity}">
<h:outputText value="#{city.name}" ></h:outputText>
<rich:dataList var="user" value="#{city.users}">
<h:outputText value="#{user.name}" ></h:outputText>
</rich:dataList>
</rich:dataList>
</h:form>
Where allCity - list of the City, and every City has list of the user inside.
See http://livedemo.exadel.com/richfaces-demo/richfaces/dataLists.jsf?c=dataList&tab=usage for example.
Backing bean:
myBean:
public class MyBean(){
private ArrayList<City> allCity= new ArrayList<City>();
@PostConstruct
public void init(){
//fill Array list
}
public ArrayList<City> getAllCity() {
return allCity;
}
}
City:
public class City{
private ArrayList<User> users= new ArrayList<User>();
public City( ArrayList<User> users){
this.users = users;
// you can get data from database in myBean, and pass it hear with cinstructor;
}
public ArrayList<User> getUsers() {
return allCity;
}
}
User
public class User{
private String name;
//constructor and others fields;
public String getName(){
return name;
}
}
Only MyBean you register as backing-bean. I show you only base structure of class, how you fill it with data is you choice.