Display key and value Map in primefaces datatable

dictionary, jsf-2, primefaces

Solution

Provided that your environment supports EL 2.2 (Java EE 6 does), and that `#{employee}` in the below example is coming from `<p:dataTable var>`, then this should do

<ui:repeat value="#{employee.advantages.entrySet().toArray()}" var="entry">
    Name: #{entry.key}, Cost: #{entry.value}
</ui:repeat>

Problem

In my Java EE 6 / JSF 2 project I have a `Map` property `advantages` in the `Employee` entity: ``` @ElementCollection private Map<String, Float> advantages; ``` The key represents the advantage name and the value represents the cost associated with the advantage name. This is mapped to a table with three columns `Employee_Id`, `Advantages` and `Advantages_Key`. I need to display all map entries in my `<p:dataTable>` which shows a `List<Employee>`. How can I achieve this?

Original source

Related problems