Please disable your adblock and script blockers to view this page

Search this blog

Tuesday 9 May 2017

Check for dirty (Uncommitted) data of current view port (page) on a button click or any event in ADF


Sometimes we need to check for uncommitted data on page and perform actions according to that, Suppose there is a button to navigate to another page but only if there is no uncommitted data in current page
We can use uncommitted data warning property of af:document to show an alert dialog but in that way, we can't execute our custom logic

Previously I have posted about checking dirty data of a transactional data control but in that, we need to check that for each data control separately that is rendering on page



In this scenario, we can check all data controls, regions or any component that makes use of data control of current viewport

This is my page with Departments table and Employes form


and see this simple code on button action to check dirty data for the current page

import oracle.adf.controller.ControllerContext;
import oracle.adf.controller.ViewPortContext;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;


    /**Method to check dirty data for current view port
     * @return
     */
    public String checkDirtyDataAction() {
        ControllerContext controllerContext=ControllerContext.getInstance();
        ViewPortContext currentRootViewPort = controllerContext.getCurrentRootViewPort();
        boolean isDataDirty = currentRootViewPort.isDataDirty();
        if (true == isDataDirty) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("There is uncommittaed data on page"));
        }
        return null;
    }

Now change any attribute's value and click on button to see result, I have changed Salary to 6000 and on button click currentRootViewPort.isDataDirty() returns true


Cheers :) Happy Learning

7 comments :

  1. Thank you Sir for this , I have designed my own uncommitted data warning popup using this

    ReplyDelete
  2. I am glad , You guys found it useful

    ReplyDelete
  3. Great, I really needed this feature as I have a lot of regions to manage. Thanks for sharing.

    ReplyDelete
  4. Jdev:11.1.1.7.1
    Hi,
    I Have a table here Active Column is there it takes Values Y or N.Suppose if i select one record in table and clicking on Edit button,if i uncheck Active record from table,that End date is set with Todays date.after uncheck i clicking on save button that uncheck record i dont want to show in table.
    @For this search query i have created for bind variables.and i have taken Active field in that View criteria i set with Value =Y then if i clicking on search button it display only check mode record only.that Active bind value i kept as a UI hints Rendered=Never like this,but this same scenario i want to do when clicking on save button.for this scenario pls help me...

    ReplyDelete
    Replies
    1. You can use this viewcrieria at AM level, Select viewObject in AM and click on edit button and then shuttle viewCriteria to selected side
      In this way View Criteria is always applies in VO and VO will show only checked record

      Delete