Alternative way to fetch VO attribute using selected in index of LOV

If you have access to the index of the selected item, then you can use value to retrieve value of any attribute of the underlying view object.

I agree that with new releases there are more direct approaches in doing so, however, depending on the business requirement, the following method may just come handy –

    public int getValue(int index){
        
        int value = 0;
        
        ViewObject vo = this.findViewObject(<View Object>);
        Row r = vo.getRowAtRangeIndex(index);
        
        try{
            value = Integer.parseInt(r.getAttribute(<Attribute Name>).toString());
        }catch(NullPointerException npe){
            value = 0;
        }
        return value;
        
    

Author- Ankit Gupta

Happy coding with Techartifact….

How to perform addition for attribute of Number type in expression language

When adding two attributes of oracle.jbo.domain.Number type in Expression Language like EmpSal and EmpBonus as below  :

#{bindings.bindings.EmpSal.inputValue + bindings.EmpBonus.inputValue}

or adding number 1000 to EmpSal as  :

#{bindings.bindings.EmpSal.inputValue + 1000}

You may get below exception :

Unexpected exception caught: java.util.MissingResourceException, msg=Can’t find resource for bundle java.util.PropertyResourceBundle, key el.convert

To Eliminate this Exception, Add EmpSal and EmpBonus as below :

#{bindings.EmpSal.inputValue.value + bindings.EmpBonus.inputValue.value}

Add ‘value’ to inputValue to remove the exception.

Happy learning in TechArtifact. 🙂

Set value in attribute in binding in Oracle ADF

Requirement – how to set value of attribute value in binding…

Solutions – you can use this expression –

JsfUtils.setExpressionValue("#{ManagedBean.empName}", "Vinay"); 

You have to add this method in JsfUtils class.

Note to call the getters and setters via your EL expression, you don’t include the get/set prefix.

 public static void setExpressionValue(String expression, Object newValue) {
    FacesContext facesContext = getFacesContext();
    Application app = facesContext.getApplication();
    ExpressionFactory elFactory = app.getExpressionFactory();
    ELContext elContext = facesContext.getELContext();
    ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);

    //Check that the input newValue can be cast to the property type
    //expected by the managed bean.
    //If the managed Bean expects a primitive we rely on Auto-Unboxing
    //I could do a more comprehensive check and conversion from the object
    //to the equivilent primitive but life is too short
    Class bindClass = valueExp.getType(elContext);
    if (bindClass.isPrimitive() || bindClass.isInstance(newValue)) {
      valueExp.setValue(elContext, newValue);
    }
  }

Happy coding in Techartifact with Vinay…