简体   繁体   中英

Fetch Id from SelectOneChoice in ADF 12c

I am using Oracle ADF12C, I have a table which has an strong text select 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);
}

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();
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM