如何使用PrimeFaces创建一个复选框数组?

时间:2018-03-16 11:40:38

标签: jsf primefaces

我需要制作一个复选框数组,如下所示

enter image description here

我有这个类java

    private Map<String, String> offices;
private Map<String, String> services;
private Map<String, Map<String, Boolean>> officeServices;

@PostConstruct
public void init() {
    offices = new LinkedHashMap<>();
    offices.put("o1", "office1");
    offices.put("o2", "office2");
    offices.put("o3", "office3");
    services = new LinkedHashMap<>();
    services.put("s1", "service1");
    services.put("s2", "service2");
    services.put("s3", "service3");
    officeServices = new HashMap<>();
    for (String office : offices.keySet()) {
        officeServices.put(office, new HashMap<String, Boolean>());
    }

}

public void submit() {
    for (Entry<String, Map<String, Boolean>> entry : officeServices.entrySet()) {
        String office = entry.getKey();
        Map<String, Boolean> services = entry.getValue();
        System.out.println(office + ": " + services);
    }
}

我有两张地图,并在另一张地图中添加一张

是以下jsf

<table>
<thead>
    <tr>
        <th>Office</th>
        <ui:repeat value="#{bean.services.values().toArray()}" var="service">
            <th>#{service}</th>
        </ui:repeat>
    </tr>
</thead>
<tbody>
    <ui:repeat value="#{bean.offices.entrySet().toArray()}" var="office">
        <tr>
            <td>#{office.value}</td>
            <ui:repeat value="#{bean.services.keySet().toArray()}" var="service">
                <td><p:selectBooleanCheckbox value="#{bean.officeServices[office.key][service]}" /></td>
            </ui:repeat>
        </tr>
    </ui:repeat>
</tbody>

这样可行,但是我需要使用真正的复选框加载字段,这可能吗?如何?

0 个答案:

没有答案