Get the selected value from selectOneChoice in ADF and not the index

Related searches

I am new to JDeveloper and ADF and I am facing a bit of a problem in getting the selected value from selectOneChoice component. This is the valuChangeListener:

public void versionValueChangeListener(ValueChangeEvent valueChangeEvent) {
    System.out.println(valueChangeEvent.getOldValue().toString());
    System.out.println(valueChangeEvent.getNewValue().toString());

}

This is giving the index of the selected choice and not the text itself. How can I get the text and not the index? This is the code for the selectOneChoice:

<af:selectOneChoice value="#{bindings.Version.inputValue}"
                                      label="#{bindings.Version.label}"
                                      required="#{bindings.Version.hints.mandatory}"
                                      shortDesc="#{bindings.Version.hints.tooltip}"
                                      id="soc3" autoSubmit="true"
                                      valueChangeListener="#{savesBean.versionValueChangeListener}">
                    <f:selectItems value="#{bindings.Version.items}" id="si3"/>
                  </af:selectOneChoice>

Thanx :)

This is how the guys at Orcle do it

How-to get the selected af:selectOneChoice Label although in my opinion it can be done in other way...

I think you better build a map in which the index will be the key and the value is the label

than in versionValueChangeListener you'll access the map something like this :

myMap.get(valueChangeEvent.getNewValue().toString());

Oracle ADF -> How to receive selected value from SelectOneChoice, Of course attribute should be defined in ViewObject. Example 2 (100% works):. You can use it method when SelectOneChoice is receiving index of element. (Not � Get the value from SelectOneChoice or LOV not the index in bean -Oracle ADF Another approach i am sharing with you.Normally we want to get selectOneChoice value and we normally get the index. We will creating an attribute in the selectOneChoice items and the selected value lable.

There is a property for the select one choice item on the jsp/jsf page that allows you to pass the actual object value or to pass the index value from the list. Click on the select one choice item in the jsp/jsf page, then hit the bindings tab at the bottom, go to the page definition (you will see it at the top of the bindings page) and the select one choice item will be highlighted in the page definition file that is now open. If you look at the property inspector from here - there is a property called "SelectItemValueMode" by default it is set to the ListIndex value, you can change it to the ListObject from here. It is the last property listed for the select one choice list object in the properties window from the page definition file.

af:SelectOneChoice, hi All, I am trying to get the selected value from the drop down and access it in backing But then they realize that this only returns the actual index of the row that was selected and not the value. I am not using ADF binding. Hello All, This post is about a common requirement of getting selected value & display value of af:selectOneChoice in the managed bean normally when we try to get selected value of selectOneChoice in the managed bean (in ValueChange/ Validator or using binding) it returns the index of that row

This is not ADF specific. This is HTML specific. Only the value of HTML <input type="radio"> element is been sent, not the value of the HTML <label> element referring it. This is true for every other HTML <input>, <select> and <textarea> element.

The soltion to your "problem" is simple: you already have all labels in your backing bean in the collection behind #{bindings.Version.items}. Just get the label from there based on the selected value.

Alternatively, set the whole complex object (containing both the value and the label) instead of only its value as item value. You only need a Converter to convert between the complex object and string.

Getting the Value from a SelectOneChoice List Using Code, But then they realize that this only returns the actual index of the row that was selected and not the value. The following little piece of code will get� Fortune Minds - Oracle ADF: How to get Selected Value or Selected Index from SelectManyChoice ADF Component If you're still getting the indexes, check this out: Go to your bindings, and in your select your list binding attribute. Then in properties inspector in the last level (others), you will see 'SelectItemValueMode'.

This worked for me

BindingContainer binding = BindingContext.getCurrent().getCurrentBindingsEntry();
JUCtrlListBinding fc =(JUCtrlListBinding) binding.get(nameOfTheDataControl);
String selectedValue = (fc.getListIterBinding().getRowAtRangeIndex(newIndexSelected).getAttribute(nameOftheColu 
mnInTheDataControl)).toString();

Getting selected value (not index) & display value of select one , Getting selected value (not index) & display value of select one choice programmatically in ADF. May 12, 2014 Ashish Awasthi Leave a comment. Sharing is� But then they realize that this only returns the actual index of the row that was selected and not the value. The following little piece of code will get you that value. What it does is access the bindings object, get the list binding, and then invoke the getSelectedValue method on it.

You can find out the solution for this on the following URL: https://blogs.oracle.com/adf/entry/getting_selected_value_from_selectonechoice

Assume we have a Model-Driven List for Deptno attribute with the display value of Dname and selectOneChoice bound to Deptno attribute in jspx page

<af:selectOneChoice value="#{bindings.Deptno.inputValue}" label="Select Department"
                            required="true" shortDesc="#{bindings.Deptno.hints.tooltip}"
                            id="soc1" autoSubmit="true">
          <f:selectItems value="#{bindings.Deptno.items}" id="si1"/>
</af:selectOneChoice>

When we want the selected value, the common mistake we do is to use the same EL bound to the value property of SelectOneChoice component, but using this we get the index of the selected item instead rather than the value. This is because when we drag and drop attribute as SelectOneChoice on to the page, SelectItems gets generated with indexes as values.

Displaying selected value on to the jspx page

In this section, we see how to get selected value without writing single line of java code. Create an outputText component with its value property bound to #{bindings.Deptno.attributeValue} instead of #{bindings.Deptno.inputValue} and make it refreshable based on list selection by adding partialTriggers property.

<af:outputText value = "Selected Value: #{bindings.Deptno.attributeValue}" id="ot1" partialTriggers="soc1"/>

The above code gives the Deptno value of the selected item. If the Deptno of 'SALES' is 30, 30 will get displayed on outputText on selecting 'SALES' from the list.

If we want 'SALES' itself to be displayed then the following EL should be used assuming Dname is the second attribute DeptView

<af:outputText value = "Display Value: #{bindings.Deptno.selectedValue ne ' ' ? bindings.Deptno.selectedValue.attributeValues[1] : ''}" id="ot2" partialTriggers="soc1"/>

Inside value change listener

Evaluating above EL expressions inside ValueChangeListener doesn't give the current selected value instead gives the previously selected value as the selected value doesn't get updated to the model by the time ValueChangeListener gets invoked.

In this case, before accessing the selected value, we need to update the model first.

Here is the sample code:

public void valueChanged(ValueChangeEvent valueChangeEvent) {
    this.setValueToEL("#{bindings.Deptno.inputValue}", valueChangeEvent.getNewValue()); //Updates the model
    System.out.println("\n******** Selected Value: "+resolveExpression("#{bindings.Deptno.attributeValue}"));
    System.out.println("\n******** Display Value: "+resolveExpression("#{bindings.Deptno.selectedValue ne ' ' ? bindings.Deptno.selectedValue.attributeValues[1] : ''}"));
}

public Object resolveExpression(String el) {      
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory =  facesContext.getApplication().getExpressionFactory();        
    ValueExpression valueExp = expressionFactory.createValueExpression(elContext,el,Object.class);
    return valueExp.getValue(elContext);
}

public void setValueToEL(String el, Object val) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ELContext elContext = facesContext.getELContext();
    ExpressionFactory expressionFactory =   facesContext.getApplication().getExpressionFactory();
    ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class);
    exp.setValue(elContext, val);
}

Get the value from SelectOneChoice or LOV not the index in bean , Get the value from SelectOneChoice or LOV not the index in bean We will creating an attribute in the selectOneChoice items and the selected value lable. Sr Java Consultant-working on Java/J2EE/Oracle ADF/Webcenter� The selectOneChoice component creates a menu-style component, which allows the user to select a single value from a list of items. The selectOneChoice component contains any number of <f:selectItem>, <f:selectItems>, or <af:selectItem> components, each of which represents an available option that the user may select.

ADF actually manages the selected value of the list item internally and the value that is exposed through the list binding itself is only the index number of the selection in the list. So in the above example, the evaluated value of bindings.EmployeesView1DepartmentId.inputValue will probably evaluate to 8 rather than 80, depending on the

Comments
  • @BalusC - this is not ADF specific, if you read his question - this is JDeveloper specific. There is a reason JDeveloper has over 3,000 pages of manual.
  • This is more convenient and easy, worked for me. Thanks
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value.