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

Sharing is Caring

Sometimes we need to check for uncommitted data on the 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 the 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

Uncommitted data

Cheers 🙂 Happy Learning

Related Posts

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

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

  1. 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…

  2. 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

Leave a Reply

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