在PrimeFaces中分组selectCheckboxMenu?

时间:2014-01-16 06:44:26

标签: primefaces jsf-2.2

有没有办法在p:selectOneMenu上应用分组(类似于p:selectCheckboxMenu)? 我已尝试过将添加分组添加到p:selectCheckboxMenu
TestBean.java

@ManagedBean
@ViewScoped
public class TestBean {

    List<SelectItem> items;
    String selectedItem;
    List<String> selectedItems;

    @PostConstruct
    public void init() {
        SelectItemGroup g1 = new SelectItemGroup("German Cars");
        g1.setSelectItems(new SelectItem[]{
            new SelectItem("BMW", "BMW"),
            new SelectItem("Mercedes", "Mercedes"),
            new SelectItem("Volkswagen", "Volkswagen")});

        SelectItemGroup g2 = new SelectItemGroup("American Cars");
        g2.setSelectItems(new SelectItem[]{
            new SelectItem("Chrysler", "Chrysler"),
            new SelectItem("GM", "GM"),
            new SelectItem("Ford", "Ford")});

        items = new ArrayList();
        items.add(g1);
        items.add(g2);
    }

    // getters and setters
}  

test.xhtml

<h:form>
    <p:selectCheckboxMenu label="Select Cars..." value="#{testBean.selectedItems}">
        <f:selectItems value="#{testBean.items}" />  
    </p:selectCheckboxMenu> 
</h:form>  

但在输出中,它只在German Cars

中显示American CarsSelectItemGroupcheckboxMenu个对象的标题)

0 个答案:

没有答案