JSF – rich:datatable and HashMap

I wanted to display the data from a Map using a rich:datatable. You can do this by using an array of the Map keys as the value for the table, and then using this to access the rest of the data in the Map.

Here is the java:

public Map<Integer,MyObject> getItems() {
   return items;
}
public List<Integer> getItemKeys() {
   List keys = new ArrayList();
   keys.addAll(getItems().keySet());
   return keys;
}

and here is the JSF:

<rich:dataTable value="#{myBean.itemKeys}" var="key" >
   <rich:column>
      <h:outputText value="#{myBean.items[key].myObjProperty}"/>
   </rich:column>
</rich:dataTable>

Obviously somewhat simplified but I think this shows how to do it!

7 thoughts on “JSF – rich:datatable and HashMap

  1. Hi, this is cool but I have a different problem I am also using same procedure but I am sending data with list and maps, so at the time of table initialization I am dumping 5 empty rows after that I am trying to modifying the empty content but it is not displaying the modified content the starnge thing is I debugged the program when I put sop the data is there in the hashmap but I am not able to figuare out what the problem is.

Leave a Reply

Your email address will not be published. Required fields are marked *