This example shows how to use SelectOneMenu which is submitted on selection event via Ajax.
<h:body style="margin-left:30px"> <h3>PrimeFaces SelectOneMenu With Ajax Example</h3> <h:form> <p:outputLabel for="menu"/> <br/> <p:selectOneMenu id="menu" value="#{itemsBean.selectedItem}"> <f:selectItem itemLabel="Select One Item"/> <f:selectItems value="#{itemsBean.items}"/> <p:ajax event="itemSelect" update=":selectedItemText"/> </p:selectOneMenu> </h:form> <br/> <h:outputText id="selectedItemText" value="#{itemsBean.selectedItem}"/> </h:body>
@ManagedBean @ViewScoped public class ItemsBean { private List<String> items = new ArrayList<>(); private String selectedItem; @PostConstruct public void postInit() { items.add("Watch"); items.add("Bottle"); items.add("Book"); items.add("Radio"); } public String getSelectedItem() { return selectedItem; } public void setSelectedItem(String selectedItem) { this.selectedItem = selectedItem; } public List<String> getItems() { return items; } }
To try examples, run embedded tomcat (configured in pom.xml of example project below):
mvn tomcat7:run-war
Dependencies and Technologies Used: