General Waters
General Waters

Reputation: 1139

How to use Map Collections with ICEfaces datatable component

I'm trying to use the values within a Map collection (doesn't matter what kind, HashMap, TreeMap), to populate an ICEfaces datatable component and display the objects properties. The only examples I've been able to find are ones that simply export the Map's values into a List collection, and use that to populate the datatable. However, I feel this is extremely wasteful and I'm now forced to maintain two collections of exact values.

Does the datatable component even support iteration over a Map's values? If not, is there possibly a better way around this then the previously mentioned solution?

For the curious, I want to use a Map collection for quick removal and it most naturally suits my data (being key based).

Upvotes: 1

Views: 2655

Answers (1)

Daniel
Daniel

Reputation: 37061

Worth a try :

I found the following solution: JSF: Using Map data in Datatable , the example in the URL refers to richfaces, but in my opinion all you need to do is use IceFaces tags , If you will use LinkedHashMap it might help you with the order...

In case that URL goes bad, here is the code:

Map<String,String> myMap;

public List<String> getMapKeys(){
    List<String> ret = new ArrayList<String>();
    for (String s : myMap.keySet())
        ret.add(s);
    return ret;
}

On the JSF page:

<rich:extendedDataTable value="#{myBean.mapKeys}" var="item"
    id="datatable">
    <rich:column width="190px" sortable="false" label="Map entries"
        id="labelColumn">
        <f:facet name="header">Map entries</f:facet>
        <h:outputText value="#{myBean.myMap[item]}" />
    </rich:column>
  </rich:extendedDataTable>

Upvotes: 1

Related Questions