Fetch Id from SelectOneChoice in ADF 12c

204 Views Asked by At

I am using Oracle ADF12C, I have a table which has an strong textselect One Choice>(Customized Query) as a column, on change of the value I need to open a popup, I have tried using value Change Listener to fetch the ID but not able to find. Any Suggestions….

I have tried using the JavaScript to fetch the ID, still it did not work

<af:selectOneChoice value="#{row.bindings.ProfileId.inputValue}"
                    label="#{row.bindings.ProfileId.label}"
                    required="#{bindings.Assets1.hints.ProfileId.mandatory}"
                    shortDesc="#{bindings.Assets1.hints.ProfileId.tooltip}"
                    id="soc7" 
                    binding="#{GenericListenerBean.assetprofileBV}">
    <f:selectItems value="#{row.bindings.ProfileId.items}"
                   id="si8"/>
    <f:validator binding="#{row.bindings.ProfileId.validator}"/>
    <af:clientListener method="profileLovValue"
                       type="valueChange"/>
</af:selectOneChoice>


function profileLovValue() {
    alert("function called");
    var lov_value = document.getElementById('soc8');

    alert("Executedd ======"+lov_value);
    var strUser = lov_value.options[lov_value.selectedIndex].value;
    alert("value ======"+strUser);
}
2

There are 2 best solutions below

0
Cedric On

There is a couple issues in your code. you are doing a :

var lov_value = document.getElementById('soc8');

when your af:selectOneChoice Html DOM ID will be something like "p1::pc2::soc7".

If you want to get the real Html DOM ID of an element from your browser, you need to right-click it in your browser and click Inspect to check the real ID in your console.

Since you are using the oracle ADF framework, you should also avoid JavaScript and use Java with built-in java ADF fonction.

—If you want to get the value of this #{row.bindings.ProfileId.inputValue} use resolveExpression as describe here https://cedricleruth.com/how-to-retreive-the-value-of-an-iterator-binding-variable-programmatically-in-adf/

//Here is how to simply retreive the value of and ADF Binding from the view El Expression :

//Below is a view example with values taken from an ADF View Object
<af:inputText id="it1" autoSubmit="true" value="#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}" />
<af:table value="#{bindings.YOUR_VO.collectionModel}" var="row">
   <af:column sortProperty="#{bindings.YOUR_VO.hints.YOUR_VO_ATTRIBUTE.name}"
               id="c1">
        <af:outputText value="#{row.YOUR_VO_ATTRIBUTE}" id="ot1"/>
    </af:column>
</af:table>

//Using below function you can easily get any of those value in your ADF Bean as follow : 
//Note: replace String by the correct type
String inputTextValue= (String)resolveExpression("#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}");
String currentRowValue= (String)resolveExpression("#{row.YOUR_VO_ATTRIBUTE}");

/**
 * Method for taking a reference to a JSF binding expression and returning
 * the matching object (or creating it).
 * @param expression EL expression
 * @return Managed object
 * @author : Duncan Mills, Steve Muench and Ric Smith's JSFUtils class
 */
public static Object resolveExpression(String expression) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
    return valueExp.getValue(elContext);
}

—If you want to get the ID of the element that trigger an event :

public void yourValueChangeEvent(ValueChangeEvent valueChangeEvent) {
    String IdOfTheObjectTriggeringTheEvent = valueChangeEvent.getComponent().getId();
}
0
Tung Vo On

I think you need change your design to avoid using JavaScript. Oracle ADF run java code on server side. In the code, you bound the selectOneChoice to assetprofileBV

binding="#{GenericListenerBean.assetprofileBV}">

You can get value of this selectOneChoice by assetprofileBV.getValue() .You can use valueChangeListener attribute to listen when value change and get value