Get updated model values in value change listener instantly, ProcessUpdates in ADF (a beauty)

Sharing is Caring

Hello All
This post talks about updating model instantly when an attribute is changed on the page level using processUpdates in ADF.
In ValueChangeListener of the component if we try to get new value from the Model layer, it always returns old value, then we have only one option to get the new value, use event object (evt.getNewValue();)
but sometimes we need to update model same timeSee how to do this

    • Created a Fusion Web Application using Departments table of HR Schema (Oracle)

 

 

    • Dropped Departments Vo on the page as a form, and created ValueChangeListener on department name field to get the new value

       

      ProcessUpdates in ADF

 

    • Now I have written a code to get DepartmentName from the current row of Departments VO (ViewObject) and to get from ValueChangeEvent

Method in AMImpl- Called in ValueChangeListener through binding Layer

/**Method to print Department Name */
    public void getDeptNameAction() {
        ViewObject depart = this.getDepartments1();
        Row curRow = depart.getCurrentRow();
        if (curRow != null) {
            System.out.println("Current Department from model is-" + curRow.getAttribute("DepartmentName"));
        }
    }

Code in ValueChangeListener – AM Method Called and Code to get new value from the event itself

    /**Value change listener for Department Name
     * @param vce
     */
    public void deptNmVCE(ValueChangeEvent vce) {
        if (vce.getNewValue() != null) {
            System.out.println("New Value in VCE-" + vce.getNewValue());
            BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
            OperationBinding ob = bc.getOperationBinding("getDeptNameAction");
            ob.execute();
        }
    }

 

    • In this case when I have changed the value on page

 

 

 

    • See the result -output from value change listener Model layer returns old value 🙁

 

 

    • Now to update the value in Model layer, I have just called processUpdates in ValueChangeListener- See the code

    /**Value change listener for Department Name
     * @param vce
     */
    public void deptNmVCE(ValueChangeEvent vce) {
        if (vce.getNewValue() != null) {
            //Method to update Model in VCE
            vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
            System.out.println("New Value in VCE-" + vce.getNewValue());
            BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
            OperationBinding ob = bc.getOperationBinding("getDeptNameAction");
            ob.execute();
        }
    }

 

  • See the result -Value is updated in model instantly (in VCE)
so this is how processUpdates works, Cheers 🙂
See one more post on this concept with different use case- Update Model Values while Validation (Exception) occurs on page on Value Change event
Happy Learning

Related Posts

An Oracle ACE, Blogger, Reviewer, Technical Lead working on Oracle ADF

0 thoughts on “Get updated model values in value change listener instantly, ProcessUpdates in ADF (a beauty)”

  1. Thanks a lot for this post. It helped me. I had a use case where I was trying to capture selected values from multiple check boxes where I was getting old values. So this post solved my problem by adding vce.getComponent().processUpdates(FacesContext.getCurrentInstance());

  2. Hi, I'm trying out a similar example of Search employees by Department Name. Dragged and dropped DepartmentID attribute in DepartmentView as SelectOneChoice(DeprtmentName is showed instead of ID) and EmployeesView as ADF Table (both from from AppModuleDataControl).
    Now Whenever i change the department in SelectOneChoice it should update the Table with employees from selected Deprtment.
    How can I do it? Step by step instruction would be helpful.

    What I've done is,
    1. I created a query in EmployeesView with BindVariable. (FilterDeptwise is my viewCriteria and DeptID is bind variable)
    ( (Employees.DEPARTMENT_ID = :DeptID ) )

    2. Then added a function in AppModuleImpl.

    public void filterEmployee(java.lang.Number DeptID) {
    EmployeesViewImpl employeesViewImpl=(EmployeesViewImpl)getEmployeesView1();
    employeesViewImpl.applyViewCriteria(employeesViewImpl.getViewCriteria("FilterDeptwise"));
    employeesViewImpl.setbindDeptId(DeptID);
    employeesViewImpl.executeQuery();
    }

    3. In Client Interface added the filterEmployee(java.lang.Number DeptID) method

    4. Above step creates filterEmployee(Number) in AppModuleDataControl
    With parameter DeptID

    How to continue from here. It is not possible to bind filterEmployee(Number) method to SelectOneChoice control. How can I achieve search operation this way?

  3. Hi,I have tried this method of processUpdate but it didnt work for me..I have a table and a LOV field on selecting the LOV value in the value change listener i have to enable few fields to edit,but it always updates the previously picked row instead of the row in which LOV is selected.I added valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance()); as he first line in my valuechangelistener.Please help.
    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *