如何在jsf datatable中访问Map键 [英] How to access Map key in jsf datatable
本文介绍了如何在jsf datatable中访问Map键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到错误 javax.el.PropertyNotFoundException:/member/apps/cms/edit.xhtml @ 228,49 value =#{props.key}:Property'key'尝试在下面显示数据表时找不到类型java.util.HashMap $ Values
。
<p:dataTable id="properties" var="props" value="#{contentEditorBacking.properties}" editable="true">
<p:column headerText="Property">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{props.key}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{props.key}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Value">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{props.value}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{props.value}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit">
<p:rowEditor />
<!-- Need to put an update on here yet -->
<p:commandLink styleClass="ui-icon ui-icon-trash" id="deleteProperty" actionListener="#{contentEditorBacking.deleteProperty}">
<f:attribute name="key" value="#{props.key}" />
</p:commandLink>
</p:column>
</p:dataTable>
这是我的contentEditorBacking的相关部分:
Here's the relevant part of my contentEditorBacking:
@ManagedBean
@ViewScoped
public class ContentEditorBacking {
private Map<String, Properties> properties = new LinkedHashMap<String, Properties>();
public Collection<Properties> getProperties() throws Exception{
return properties.values();
}
public static class Properties{
private String key;
private String value;
public Properties(String key, String value) {
super();
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "key=" + key + ", value=" + value + "";
}
}
}
怎么能我从我的属性映射中访问键值?
How can i access the key value from my properties map?
推荐答案
在即将推出的JSF 2.2之前,< h:dataTable>
/ < p:dataTable>
不支持集合< E>
。它仅支持列表< E>
。
Until the upcoming JSF 2.2, the <h:dataTable>
/<p:dataTable>
doesn't support Collection<E>
. It only supports among others List<E>
.
您需要替换
public Collection<Properties> getProperties() throws Exception{
return properties.values();
}
按
private List<Properties> propertiesAsList;
public List<Properties> getProperties() throws Exception{
return propertiesAsList;
}
在地图初始化后直接执行此操作
and somewhere directly after map's initialization do this
propertiesAsList = new ArrayList<Properties>(properties.values());
(注意:不要在吸气剂内进行!)
这篇关于如何在jsf datatable中访问Map键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文