Requirement: I have an af:selectOneChoice in which I want to populate the data programmatically from the Java class.
Solution: For solution of the above requirement follow the steps as shown below:
Step 1: Create an Oracle ADF Fusion Web Application.
Step 2: Create a Managed Bean with the name as MyBean.java.
The complete code for the MyBean.java class is shown below:
package susantotech.com; import java.util.ArrayList; import java.util.List; import javax.faces.model.SelectItem; public class MyBean { List<SelectItem> fruitNameList; public MyBean() { } public void setFruitNameList(List fruitNameList) { this.fruitNameList = fruitNameList; } public List getFruitNameList() { if (fruitNameList == null) { fruitNameList = new ArrayList<SelectItem>(); fruitNameList.add(new SelectItem("i1", "Apple")); fruitNameList.add(new SelectItem("i2", "Banana")); fruitNameList.add(new SelectItem("i3", "Mango")); fruitNameList.add(new SelectItem("i3", "Orange")); } return fruitNameList; } }
Step 3: Drag and drop Choice List from the Component Palette onto the demo.jspx.
Click on the Bind button
Select the Value binding as “#{pageFlowScope.MyBean.fruitNameList}”
Click OK
Click Next
Set Label as Fruits Name > Click Finish
Thus, the complete demo.jspx page is shown below:
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="" version="2.1" xmlns:f="" xmlns:af=""> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="demo.jspx" id="d1"> <af:form id="f1"> <af:selectOneChoice label="Fruits Name" id="soc1"> <f:selectItems value="#{pageFlowScope.MyBean.fruitNameList}" id="si1"/> </af:selectOneChoice> </af:form> </af:document> </f:view> </jsp:root>
Save all and run the application. Thus, the ran application is shown below: Here we can see the Fruits Name are populated from the Managed Bean.
Hence, the solution to our requirement.
If you like the post please comment, share, and do join me on Facebook. Please subscribe to my YouTube Channel for video tutorials.
Thanks & Regards,
Susanto Paul
640 total views, 4 views today