gpt4 book ai didi

java - 如何访问jsf数据表中的Map键

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:49:20 24 4
gpt4 key购买 nike

我收到错误 javax.el.PropertyNotFoundException:/member/apps/cms/edit.xhtml @228,49 value="#{props.key}": Property 'key' not found on尝试显示下面的数据表时键入 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 的相关部分:

@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 + "";
}

}
}

如何从我的属性映射中访问键值?

最佳答案

直到即将到来的 JSF 2.2,<h:dataTable>/<p:dataTable>不支持 Collection<E> .其中仅支持 List<E> .

你需要更换

public Collection<Properties> getProperties() throws Exception{
return properties.values();
}

通过

private List<Properties> propertiesAsList;

public List<Properties> getProperties() throws Exception{
return propertiesAsList;
}

在 map 初始化之后直接在某处执行此操作

propertiesAsList = new ArrayList<Properties>(properties.values());

(注意:不要在 getter 内部这样做!)

关于java - 如何访问jsf数据表中的Map键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11550354/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com