SelectManyButton is used to choose multiple items from a list using buttons.
Documentation<h:form> <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5"> <h:outputText value="Font:" /> <p:selectManyButton value="#{selectManyView.selectedOptions}"> <f:selectItem itemLabel="b" itemValue="b" /> <f:selectItem itemLabel="u" itemValue="u" /> <f:selectItem itemLabel="i" itemValue="i" /> </p:selectManyButton> <p:commandButton value="Submit" update="display" icon="pi pi-check" /> <p:spacer /> <h:outputText value="Selected:" /> <p:dataList id="display" value="#{selectManyView.selectedOptions}" var="font" emptyMessage="No fonts selected"> <h:outputText value="#{font}" style="font-weight: bold" /> </p:dataList> </h:panelGrid> </h:form>
@Named @RequestScoped public class SelectManyView { private List<String> selectedOptions; private List<String> selectedOptions2; private List<Theme> selectedThemes; private List<Theme> selectedThemes2; private List<Theme> themes; @Inject private ThemeService service; @PostConstruct public void init() { themes = service.getThemes(); } public List<Theme> getThemes() { return themes; } public void setService(ThemeService service) { this.service = service; } public List<String> getSelectedOptions() { return selectedOptions; } public void setSelectedOptions(List<String> selectedOptions) { this.selectedOptions = selectedOptions; } public List<Theme> getSelectedThemes() { return selectedThemes; } public void setSelectedThemes(List<Theme> selectedThemes) { this.selectedThemes = selectedThemes; } public List<String> getSelectedOptions2() { return selectedOptions2; } public void setSelectedOptions2(List<String> selectedOptions2) { this.selectedOptions2 = selectedOptions2; } public List<Theme> getSelectedThemes2() { return selectedThemes2; } public void setSelectedThemes2(List<Theme> selectedThemes2) { this.selectedThemes2 = selectedThemes2; } }
@Named @ApplicationScoped public class ThemeService { private List<Theme> themes; @PostConstruct public void init() { themes = new ArrayList<>(); themes.add(new Theme(0, "Nova-Light", "nova-light")); themes.add(new Theme(1, "Nova-Dark", "nova-dark")); themes.add(new Theme(2, "Nova-Colored", "nova-colored")); themes.add(new Theme(3, "Luna-Blue", "luna-blue")); themes.add(new Theme(4, "Luna-Amber", "luna-amber")); themes.add(new Theme(5, "Luna-Green", "luna-green")); themes.add(new Theme(6, "Luna-Pink", "luna-pink")); themes.add(new Theme(7, "Omega", "omega")); } public List<Theme> getThemes() { return themes; } }