【发布时间】:2012-12-29 21:48:47
【问题描述】:
我需要使用<h:dataTable> 显示Map。我的支持 bean 有一个 Map 属性,如下所示:
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");
}
}
然后在 JSF 页面中,我尝试将此 Map 属性绑定到 <h:dataTable> 的 value 属性。
<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>
错误提示 getKey 和 getValue 不存在。我可以理解这不是正确的方法。如何使用<h:dataTable> 呈现Map?
【问题讨论】:
标签: jsf datatable hashmap treemap