Wednesday, October 1, 2014

Programmatically populate the af:selectOneChoice component in Oracle ADF?

Step1

Create a Java List of SelectItems and create getter setter for that as below

    List<SelectItem> customList;

    public void setCustomList(List<SelectItem> customList) {
        this.customList = customList;
    }

    public List<SelectItem> getCustomList() {
        return customList;
    }
 

Step2

 

Modify the getter method with the logic to return the list of items

 

    public List<SelectItem> getCustomList() {
        if (customList == null) {
            customList = new ArrayList<SelectItem>();
            customList.add(new SelectItem("Value 1","Label 1"));
            customList.add(new SelectItem("Value 2","Label 2"));
            customList.add(new SelectItem("Value 3","Label 3"));
            customList.add(new SelectItem("Value 3","Label 4"));
            customList.add(new SelectItem("Value 5","Label 5"));
        }
        return customList;
    }
 

Step3 

 

Configure the jsff/jspx as below to refer the select items from the bean getter method created above


 <af:selectOneChoice label="Custom List" id="soc1">
     <f:selectItems value="#{CustomerBean.customList}" id="si1"/>
</af:selectOneChoice>

No comments:

Post a Comment