In this tutorial you will see that how to populate selectOneChoice list from managed bean, sometimes we need to use custom list that are not model driven, this scenario can be implemented there
follow steps -
follow steps -
- First of all create a fusion web application and a page in it
- Now create a variable of type java.util.List in managed bean, and generate its accessors
- this list contains value of type javax.faces.model.SelectItem; that is supported by af:selectOneChoice
- now time to add values in list, so to add values in this list i have written this code in getter of variable
- Managed bean part is done, now add this to view layer
- Drop choice list in page from component palette
List<SelectItem> customList; public void setCustomList(List<SelectItem> customList) { this.customList = customList; } public List<SelectItem> getCustomList() { return customList; }
public List<SelectItem> getCustomList() { if (customList == null) { customList = new ArrayList<SelectItem>(); customList.add(new SelectItem("i1","Item 1")); customList.add(new SelectItem("i2","Item 2")); customList.add(new SelectItem("i3","Item 3")); customList.add(new SelectItem("i3","Item 4")); customList.add(new SelectItem("i5","Item 5")); } return customList; }
- Now bind choice list to bean List
- See the page source after whole setup-
- Run this page and see programmatic choice list-
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="listPage.jspx" id="d1"> <af:form id="f1"> <af:panelGroupLayout id="pgl1" layout="vertical" halign="center"> <af:spacer width="10" height="10" id="s1"/> <af:selectOneChoice label="Custom List" id="soc1" contentStyle="font-weight:bold;color:darkgreen;"> <f:selectItems value="#{ListPolulatebean.customList}" id="si1"/> </af:selectOneChoice> </af:panelGroupLayout> </af:form> </af:document> </f:view> </jsp:root>