有没有办法在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 Cars
和SelectItemGroup
(checkboxMenu
个对象的标题)