Reset Binding Value from InputText in Oracle ADF

Use Case – We have one jsff page and contains some inputtext .On same page there is one Save button and one Cancel button.When user came to the page and try to enter some value in input text field and user click on Cancel button, its not resetting InputText value.When user come on same page again then he can able to see my previously entered value in Input Text though user clicked on cancel.

Normal developer will wrote Action Listener on Cancel Button and wrote below code

input.resetValue() ;

But its will work (reset values).Setting value in input will not work like


Few developers will think, why cant we use resetActionListener. It will work for sure,but if you make autoSubmit of inputText to true, it will not work.
Reason- InputText has autoSubmit set to true, which submit the values to model immediately after updating it, resetActionListener resets values only if changes are not populated to model.

For this case use below code.Get current row and do REFRESH_FORGET_NEW_ROWS

    Row r1=vo.getCurrentRow(); 
    r1.refresh(oracle.jbo.Row.REFRESH_UNDO_CHANGES |  Row.REFRESH_FORGET_NEW_ROWS);  

Note : If you don’t need autoSubmit, you can just remove it and use resetActionListener without any bean method to undo current row changes

It will reset binding value of input text.

Happy learning with Vinay Kumar 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…

getting binding of component from one managed bean to another

Today i got one of the requirment to get the binding of some component which is binding in another managed bean.
This is something tedious requirment i have.. Well in JSF 2.0 you can get very easily by using below code

        FacesContext context = FacesContext.getCurrentInstance();
        BEAN bean = (RegionNavigationListener)context.getApplication().evaluateExpressionGet(context, "#{BEAN}", BEAN.class);

You can write above code as below as well

FacesContext fctx = FacesContext.getCurrentInstance();
Application application = fctx.getApplication();
ExpressionFactory expressionFactory = application.getExpressionFactory();
ELContext context = fctx.getELContext();
ValueExpression createValueExpression = expressionFactory.createValueExpression(context, "#{pageFlowScope.PageFlowScopeBean}",PageFlowScopeClass.class);
PageFlowScopeClass pageFlowScopeInstance =(PageFlowScopeClass) createValueExpression.getValue(context);