Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label processUpdates. Show all posts
Showing posts with label processUpdates. Show all posts

Monday 7 April 2014

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

Hello All,

This posts talks about updating model instantly when a attribute is changed on page level.
In ValueChangeListener of component if we try to get new value from Model layer, it always returns old value, then we have only one option to get new value, use event object (evt.getNewValue();)
but sometimes we need to update model same time
So how to do this-

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


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





  • Now i have written a code to get DepartmentName from 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 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 value on page 



  • see the result -output from valuechangelistener- Model layer returns old value :-(


  • Now to update 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 usecase- Update Model Values while Validation (Exception) occurs on page on Value Change event
Happy Learning

Monday 1 July 2013

Update Model Values while Validation (Exception) occurs on page on Value Change event- Oracle ADF (processUpdates)

In ADF when we have some validation on page and we try to submit any value, but normally after validation (Exception) values are not updated in Model until exception is handled.
This tutorial is about how to update values in Model while exception on page.
For a scenario, i have used department (default HR Schema) table and form in a JSP XML fragment inside bounded taskflow.
In form Department Id and Department Name is mandatory field, ManagerId and Location Id has auto submit true.
  • I have dropped createInsert,Execute,Commit and Rollback as buttons on page




  • Click on create button and first enter manager id, as this field has autosubmit true so on submission of value page is validated and then Required Fields throw exception, and after exception you can see that manager id & location id is not updated in Model, and not reflected in af:table also.


  •  Normally what we do, set immediate true to skip validations, but in this case i have witten ValueChangeListener on manager Id and Location Id to process values in Model.- see code

  •     public void mangrIdVCE(ValueChangeEvent vce) {
            vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
        }
    

  • processUpdates() method of UIComponent class perform the coponent tree processing for all facet of this component by Update Model Values phase of request processing, and pushes data to Model

  • Now after calling this method, run application- Now values are populated in af:table and validation is still there on page


  • this approach can be used while using validators on page and want to process some values after validation (as conditional validation of some fields etc)
  • Download sample application -Sample App