本文介绍了如何在selectOneMenu中对selectItem进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用展示柜中的示例将selectOneMenu中的selectItem分组:

I would like to use the example from the primefaces showcase to group selectItems in selectOneMenu:

<h:outputText value="Grouping: " />
    <p:selectOneMenu value="#{formBean.car}">
        <f:selectItem itemLabel="Select One" itemValue="" />
        <f:selectItems value="#{formBean.cars}" />
    </p:selectOneMenu>

我的问题是,没有Bean的实现.现在我不知道如何在方法getCars()中实现selectItems的分组.而且我找不到其他示例.

My problem is, that there is no implementation of the bean. Now I don't know, how to implement the grouping of the selectItems inside the method getCars(). And I can't find any other example.

推荐答案

展示柜#{formBean}的源代码可用此处.这是相关的摘录:

The source code of the showcase's #{formBean} is available here. Here's an extract of relevance:

private List<SelectItem> cars;

public FormBean() {
    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")});

    cars = new ArrayList<SelectItem>();
    cars.add(g1);
    cars.add(g2);
}

因此,您丢失的密钥是 SelectItemGroup .

Thus, your missing key is SelectItemGroup.

这篇关于如何在selectOneMenu中对selectItem进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 14:15