Tag Archives: selectOneChoice

How To in Jdeveloper ADF Tutorials – set and get SelectOneChoice values

Imagine that you have a ViewObject added to the Application Module and you want to add this view instance as a selectonechoice for the base VO in your UI.


Lets have a setup as ‘DeliveryRuleView’ VO as a base datasource and for the column ‘CapTrgTyp’ you are going to add a LOV list of values coming from ‘DeliveryTriggerType’ VO

The following screenshot will show a VO ‘SystemDictionaryView’ added to the AM as a View Instance ‘DeliveryTriggerType’. The ‘SysemDictinaryView’ will list the values based on the ‘Subcategory’ provided during runtime.

To Map this to a select one choice in the UI. You will have to have the list binding created as shown in the screenshot.

  • The Base Data Source is selected as ‘DeliveryRuleView’ and the List Data Source is selected as ‘DeleiveryTriggerType’.
  • The Data Mpping is done against the ‘CaptrgType’ from ‘DeliveryRuleView’ and the ‘SubCategory’ attribute from the ‘DeliveryTriggerType’.
  • The List Binding will have another attribute ‘Value’ as a Display Attribute. The binding is named as Deliverytrigger’
  • Have an iterator defined for the ‘DeliveryTriggerType’ View instance from AM and name it as ‘DeliveryTriggerTypeIterator’

in the jsff page you will have the selectonechoice code as

<af:selectOneChoice label="Trigger" id="deliveryTrigger" value="#{pageFlowScope.backing_bean.deliveryTrigger}" required="true" autoSubmit="true">
<f:selectItems id="si131" value="#{bindings.DeliveryTrigger.items}"/>

When you look closely, the value of the selectonechoice is mapped to the deliveryTrigger value in the managed bean and we have the selectItems bounded to the pagedef list bindings as ‘#{bindings.DeliveryTrigger.items}’

Create Operation

So during Creation of a record in ‘DeliveryRuleView’ the list will be populated from ‘DeliveryTriggerType’ instance. The user selects the option in the list and presses the save button.

Since selectonechoice stores only the index value, the value that is stored will point to the index value within the selectonechoice. for e.g if the user select’s choice ‘Third Option in the list'(underlying SubCategory as ‘THIRD_VALUE’) then the value for deliverTrigger will store as 2 as the index starts from 0.

So how to map this to the correct selection?.

Have an actionlistner for the save button and have the following code that computes the correct selection for the select one choice

What this method does:

  • Get the iterator binding corresponding to the iterator name passed through ‘iteratorName’, in our case this will be ‘DeliveryTriggerTypeIterator’
  • Get the Row corresponding to the index passed , this will be ‘deliveryTrigger’ which holds the index value of the selectonechoice
  • Get the ‘SubCategory’ value from the corresponding row and return it.

private String getListValueFromIndex(int index, String iteratorName) {
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry()

DCIteratorBinding dciterContainer =

Row ri = dciterContainer.getRowAtRangeIndex(index);
String val = (String)ri.getAttribute("SubCategory");
return val;

The value returned will have the underlying subCategory value(‘THIRD_VALUE’) corresponding to the value selected in the UI as ”Third Option in the list”. Then the value can be saved to the ‘Captrgtyp’ column of the DB for ‘DeliveryRuleView’

Edit Operation

During the Edit operation of the record, we have to fetch the corresponding value for the selected record and populate for ‘Captrgtyp’ attribute in the selectonechoice.

What this method does:

  • The currentRow and the ‘Captrgtyp’ is passed as attribName to the method
  • Get the iterator binding corresponding to the iterator name passed through ‘iteratorName’, in our case this will be ‘DeliveryTriggerTypeIterator’
  • Get the RowSetIterator from the iiterator binding
  • Iterate over the record and check if the value is equal to the value of the ‘SubCategory’ from the rowSetIterator
  • If it’s equlal then save the index value to a variable ‘i’
  • Finally return the value ‘i’ which corresponds to corresct value in the selectonechoice

private Integer getListValueIndex(Row row, String iteratorName, String attribName) {
int i = 0;
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry()

DCIteratorBinding dciterContainer =

RowSetIterator rs = dciterContainer.getRowSetIterator();
Row ri = rs.first();
for(int index = 0;index < rs.getRowCount(); index ++){
String temp = (String)ri.getAttribute("SubCategory");
String ar = (String)row.getAttribute(attribName);
if(ar != null && temp.equals(ar.toString().trim())){
i = index;
ri = rs.next();

return i;


af:selectonechoice not getting updated

Today i had an interesting problem at work. The issue is that the user selects the value from a selectonechoice and moves to the next page and when he returns back to the same old page the selectonechoice is not updated with the value that is selected previously.

the selectonechoice is not bounded to any of the bindings and we manually create the list using the managed bean. here is the base snippet which resembles the problem

selectOneChoice simple="true" value="#{Bean.list.itemNo}" id="soc1" unselectedLabel="Please Select">
 selectItems value="#{Bean.listItems}"/>

while debugging the value the value is all available but somehow the value is not shown in the selectonechoice. The value is again moves to the “Please Select” option specified in the unselectedLabel when the user moves back to the original page.

couple of things i tried which failed
1)binding to the bean and getting the value

2) having the value as “#{Bean.list[‘itemNo’]}”

finally I got to see the following warning in the log saying

13-Jul-2011 20:27:54 oracle.adfinternal.view.faces.renderkit.core.xhtml.SimpleSelectOneRenderer _getSelectedIndex
WARNING: Could not find selected item matching value "1" in CoreSelectOneChoice[UIXEditableFacesBeanImpl, id=soc1]

This warning gave me a hint to think the problem in a different way and leads to the solution

Actually the list that we are manipulating assigns the value on the fly like


List<SelectItem> items = new Arraylist();


//inside the method

items.add(new SelectItem(code.getItemlabel(), code.getItemValue()));


the above code has to rewritten as shown to solve the above mentioned issue

//inside the method

SelectItem item = new SelectIem();


item.setValue(code.getItemValue()); //here the value should be an Integer value
//if the value is a String then this has to be like