Reputation: 169
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?
Upvotes: 8
Views: 16686
Reputation: 91
this works for me, and this is my map in bean Map:
<p:dataTable id="dtbAddedRoles" value="#{controllerUserCreationMain.mapUtil.entrySet().toArray()}"
var="roleAdded">
<p:column headerText="Role">
<p:outputLabel value="#{roleAdded.key.roleName}" />
</p:column>
</p:dataTable>
Upvotes: 7
Reputation: 630
I know that answer is too late, but maybe for others it will be useful.
Assume your haspmap is defined as follows:
HashMap<String, BigDecimal> myHashMap;
public List<Entry<String, BigDecimal>> getMyHashMapEntryList() {
return new ArrayList(myHashMap.entrySet());
}
in your UI:
<p:dataTable value="#{yourBean.myHashMapEntryList}" var="myEntry">
in here reference as: #{myEntry.key} #{myEntry.value}
</p:dataTable>
Upvotes: 0
Reputation: 1108722
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>
Upvotes: 21