I need to display Map
using <h:dataTable>
. My backing bean has a Map
property as below:
public class Bean {
private Map<Integer,String> map; // +getter
@PostConstruct
public void init() {
map = new TreeMap<Integer,String>();
map.put(1,"Sasi");
map.put(2,"Pushparaju");
map.put(3,"Venkat Raman");
map.put(3,"Prabhakaran");
}
}
Then in JSF page I am trying to bind this Map
property to the value
attribute of <h:dataTable>
.
<h:dataTable border="1" value="#{bean.map}" var="map">
<h:column id="column1">
<f:facet name="header">
<h:outputText value="UserId"></h:outputText>
</f:facet>
<h:outputText value="#{map.getKey}"></h:outputText>
</h:column>
<h:column id="column2">
<f:facet name="header">
<h:outputText value="Email Id"></h:outputText>
</f:facet>
<h:outputText value="#{map.getValue}"></h:outputText>
</h:column>
</h:dataTable>
It is giving en error that getKey
and getValue
is not present. I can understand that this is not the correct way to do it. How can I present a Map
using <h:dataTable>
?
Entry
is a NonSerializable
Interface. Doesn't affect when usingViewScoped
Bean. [p.s I'm usingLinkedHashMap
] ? – Fluker