简体   繁体   English

在JSF或Primefaces数据表中编辑哈希图

[英]Edit hashmap in JSF or Primefaces datatable

I have an object that represents a service provider. 我有一个代表服务提供者的对象。 In that object I have this hashmap 在那个对象中,我有这个哈希图

private Map<MetaDataKeys, String> metaData;

The "MetaDatatKeys" is a enum that looks like this, “ MetaDatatKeys”是一个看起来像这样的枚举,

public enum MetaDataKeys {
    PROVIDER_NAME, PROVIDER_CONTACT_NAME, PROVIDER_SERVICE_RADIUS;
}

I would like to display the hashmap key/value pairs in a datatable or similar for editing, something along the lines of, 我想在数据表或类似表格中显示哈希映射键/值对,以进行编辑,类似

            <p:dataTable id="providerDatatable" var="infoMap" value="#{editUserBean.editUser.metaData}">
                <p:column><h:outputText value="#{infoMap.key.metaData}"/></p:column>
                <p:column><h:inputText value="#{infoMap.key.value}"/></p:column>
            </p:dataTable>

In my backing bean "editUser" is the object that contains the map. 在我的后备bean中,“ editUser”是包含映射的对象。

what is the best way to go about this? 最好的方法是什么? I have not been successful in even getting the table to render and populate with values. 我什至没有成功地使表呈现和填充值。 In searching most examples use a string or a primitive for the key. 在搜索大多数示例时,请使用字符串或原语作为关键字。

You should make iteration in the datatable by Map.entrySet() it's better way. 您应该通过Map.entrySet()在数据表中进行迭代,这是更好的方法。 If you try to do itaration by Map.keySet() and than take value by key you can take O(n^2). 如果您尝试通过Map.keySet()进行感测,而不是通过键获取值,则可以采用O(n ^ 2)。

For your task realisation looks like: 为您的任务实现看起来像:

<p:dataTable id="providerDatatable" var="infoMap" value="#{editUserBean.editUser.metaData.entrySet()}">
    <p:column><h:outputText value="#{infoMap.key}"/></p:column>
    <p:column><h:inputText value="#{infoMap.value}"/></p:column>
</p:dataTable>

To edit table row you can you use p:cellEditor more info about this component you can find at the Primefaces show case 要编辑表格行,您可以使用p:cellEditorPrimefaces展示柜中找到有关此组件的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM