ADF Basics: Get display and base value of POJO based SelectOneChoice

Sharing is Caring

Previously I have posted about populating POJO based selectOneChoice programmatically

and this post is about getting selected value of POJO base selectOneChoice (both display value and base value)
We can get base value of selectOneChoice simply using value property but to get display value we have to iterate over the list of items and find display value on basis of Base value
So here I have created a POJO based selectOneChoice, for that declared a List in the managed bean to populate list items and a String variable to hold the selected value of choice list


 //String variable to hold selected value of selectOneChoice
 String selectedVal;

public void setSelectedVal(String selectedVal) {
this.selectedVal = selectedVal;

public String getSelectedVal() {
return selectedVal;

//List variable to populate selectOneCoice
List<SelectItem> customList;

public void setCustomList(List<SelectItem> customList) {
this.customList = 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("i4", "Item 4"));
customList.add(new SelectItem("i5", "Item 5"));
return customList;

and how this List and String variable is mapped on the page-

<af:selectOneChoice label="Select Value" id="soc1"
                            <f:selectItems value="#{viewScope.GetValuePojoListBean.customList}" id="si1"/>

Then dropped a button on the page and created an actionListener in the managed bean to get both values

    /**Method to get Selected Value in selectOneChoice
     * @param actionEvent
    public void getDisplayAndBaseValueFromList(ActionEvent actionEvent) {
        //Iterate over List to get Display Value
        for (SelectItem si : customList) {
            if (si.getValue().toString().equalsIgnoreCase(selectedVal)) {
                System.out.println("SELECTED VALUE IS- " + selectedVal + " DISPLAY VALUE IS- " + si.getLabel());

Now run and check application, Page looks like this-

Select a value and click on the button-

The output on console-

Sample ADF Application (Jdev 12.1.3)- Download
Cheers 🙂 Happy Learning

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *