This example shows how to use SelectCheckboxMenu which is submitted on change event via Ajax.
<h:body style="margin-left:30px"> <h5>PrimeFaces SelectCheckboxMenu With Ajax Example</h5> <h:form> <p:selectCheckboxMenu id="menu" value="#{itemsBean.selectedItems}" label="Items" filter="true" filterMatchMode="contains"> <f:selectItems value="#{itemsBean.items}"/> <p:ajax event="change" update="selectedItemText"/> </p:selectCheckboxMenu> <h:outputText id="selectedItemText" value=" #{itemsBean.selectedItems}"/> </h:form> </h:body>
@ManagedBean @ViewScoped public class ItemsBean { private List<String> items = new ArrayList<>(); private List<String> selectedItems; @PostConstruct public void postInit() { items.addAll(Arrays.asList ("Watch", "Bottle", "Book", "Radio", "Monitor", "Laptop", "Headphones", "TV", "Disk", "Note Book", "Cell Phone")); } public List<String> getItems() { return items; } public void setSelectedItems(List<String> selectedItems) { this.selectedItems = selectedItems; } public List<String> getSelectedItems() { return selectedItems; } }
To try examples, run embedded tomcat (configured in pom.xml of example project below):
mvn tomcat7:run-war
Dependencies and Technologies Used: