How to check ifdirty (is modified) for View Object?

Requirement – Checking if data modified in viewobject ADF

Solution-You can use isDirty() method provided by API to get status

 DCBindingContainer bind =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
        JUCtrlHierBinding object = (JUCtrlHierBinding)bind.findCtrlBinding("DepartmentVO1"); // or get ViewObject form Iterator in ADFUtils.
        ViewObject deptVo = object.getViewObject(); 
        Boolean b = deptVo.getApplicationModule().getTransaction().isDirty();This gives Boolean value of True/False. 

another way

DCBindingContainer dcBindingContainer=(DCBindingContainer)
BindingContext.getCurrent().getCurrentBindingsEntry();
if(dcBindingContainer.getDataControl().isTransactionModified()){
//Code goes here...
}

few more use case i found on internet i.e http://oracleadfhowto.blogspot.de/2012/03/iterator-uncommitted-data-availability.html, so thought of sharing that as well –

1. If you are using iterator based UI component like table:
Expression #{row.row.entities[0].entityState} will return state viz. (0 – New, Modified – 2, Unmodified – 1, Initialized – -1 where row refers to the table node and row.row is the instance of row in the iterator/table.

The following expression also notify that there is dirty data available –

-> #{!bindings.EmployeesView1Iterator.dataControl.TransactionDirty}   // this statment will notify that there is uncommitted or unsaved data in the iterator
-> #{!bindings.Commit.enabled}
-> #{!controllerContext.currentRootViewPort.dataDirty}
-> #{!controllerContext.currentViewPort.dataDirty} 

Happy ADF learning with Vinay in techartifact….

Sorting of Programmatic or transient view object in Oracle ADF

Tip- to sort a transient view object

When we use transient View Object to store data to represent in UI or manipulate business logic.
We may need to sort these Transient ViewObjects based on certain attribute.Add this below code to represent sort data.

transVo.setSortBy("AttributeName");
transVo.setQueryMode(ViewObject.QUERY_MODE_SCAN_VIEW_ROWS);
transVo.executeQuery();

Happy coding with Vinay in Techartifact …..

Creating new row of view object in ADF | Techartifact

Requirment – Creating new rows through the view object

Solution-Create a new view row by calling createRow() on the view object as shown in the following code snippet:

/**The createEmployee is a custom method defined in application
* module implementation class.
*/


public void createEmployee () {
//Get the view object
ViewObject employee= findViewObject("EmployeeVO");
// Create a row and fill in the columns.
Row row = employee.createRow();
row.setAttribute("Name", "Vinay");
row.setAttribute("EmpId", 1);
//Insert row in to the default row set
employee.insertRow(row);
}


You can also use createAndInitRow(AttributeList initVals) on the view object to create a new view row. This API allows you to initialize the row with an attribute list.