Code: Select all
<h:form id="myForm">
<p:selectOneMenu value="#{viewBean.selectedFood}">
<f:selectItem itemLabel="Select One" itemValue=""/>
<f:selectItems value="#{viewBean.foodList}"/>
<p:ajax update=":myForm:text"/>
</p:selectOneMenu>
<br/>
<h:outputText id="text" value="#{viewBean.selectedFood}"/>
</h:form>
Code: Select all
@ManagedBean
@ViewScoped
public class ViewBean implements Serializable {
private List<String> foodList;
private String selectedFood;
public ViewBean() {
}
@PostConstruct
public void init() {
foodList = new ArrayList<String>();
foodList.add("Pizza");
foodList.add("Pasta");
foodList.add("Hamburger");
}
//setter, getter
}