您可以在selectOneMenu Primefaces中选择组选项吗

时间:2018-12-01 09:47:22

标签: java jsf primefaces

我似乎为我的SelectItemGroup设置了值,但是无法选择分组选项,并且在我的selectedValue中没有设置值

<p:selectOneMenu value="#{controller.selectedValue}">
        <f:selectItem itemLabel="#{bundle.defautlItem}"/>
        <f:selectItems value="#{controller.findAll()}" var="gs" itemLabel="#{gs.name}" itemValue="#{gs}"/>    
</p:selectOneMenu>


public List<SelectItem> findAll() {
    List<Company> companies = companyFacade.findAllWithSelfTrue();
    Map<Company, List<Branch>> companiesMap = new HashMap<>();
    for(Company c : companies) {
        List<Branch> branches = branchFacade.findWithCompany(c);
        companiesMap.put(c, branches);
    }

    List<SelectItem> resultList = new ArrayList<>();
    companiesMap.forEach((key,value) -> {
        SelectItemGroup sig = new SelectItemGroup();
        SelectItem[] selectItems = new SelectItem[value.size()];
        for(int i = 0; i < value.size(); i++) {
            selectItems[i] = new SelectItem(value.get(i), value.get(i).getActorName());
        }
        sig.setSelectItems(selectItems);
        sig.setValue(key); \\set value for grouping options?
        sig.setLabel(key.getName());
        resultList.add(sig);
    });
    return resultList;
}

0 个答案:

没有答案