Time for action – using the MultiSelectListbox component
Let us see how to create a MultiSelectListbox component to display categories and its subcategories based on the selected category, by performing the following steps:
- Instantiate
List<SelectItem>
instances with details of categories and subcategories:public class CatalogController { private List<SelectItem> categories; private String selectedCategory; public CatalogController() { categories = new ArrayList<SelectItem>(); SelectItemGroup homeAppliancesGrp = new SelectItemGroup("Home Appliances"); SelectItemGroup homeDecorGrp = new SelectItemGroup("Home & Decor"); SelectItem clocks = new SelectItem("Wall Clocks"); SelectItem candleHolders = new SelectItem("Candle Holders"); SelectItem artPrints = new SelectItem("Art Prints"); homeDecorGrp.setSelectItems(new SelectItem[...