Please disable your adblock and script blockers to view this page

Search this blog

Showing posts with label undo changes. Show all posts
Showing posts with label undo changes. Show all posts

Monday 1 May 2017

Undo row selection of af:table in selection listener method conditionally


Recently I have seen a question on OTN Jdeveloper forum and It was about table selection listener
Requirement is like this suppose user has to check a condition after selecting a row and if that condition is true only then new row will be selected else selected row should be previous one

It means undo row selection on validation(condition) failure
So In this post I am implementing same scenario and here I am using Departments table of HR Schema to prepare model and condition is that user should be able to select new row only if ManagerId is not null

Wednesday 2 April 2014

Performing Partial Rollback (Undo Changes) operation in ADF, Stay on current row after rollback

Hello All ,
This post talks about a common requirement of using partial rollback in ADF

Suppose there is two tables on page Departments and Employees, and i have changed one row in Departments table and same time created a row in Employees table, now i want to rollback the changes done in Departments table only

In this case if i use default Rollback operation then it will not only undo the changes of Department table but also remove the newly created row of Employees table
but this was not my purpose.

So to do this kind of things we can use partial rollback operation
  • I have created a fusion web application (Model & VC) using Departments & Employees Table of Oracle's default HR Schema

  • Now drop departments & employees VO on page with it's default operations (CreateInsert, Delete, Execute, Commit & Rollback) and a button to execute partial rollback of departments ViewObject


  • Here in this example i am creating partial rollback for Departments VO only, so to do this add a new transient attribute in Departments Vo to get current state of each row




  • How to get state of each row , in RowImpl class of departments ViewObject , write this code in getter of transient attribute or see my previous blog-post Identifying Modified/newely added row in af:table, get all modified rows of viewobject in bean

  •     /**
         * Gets the attribute value for the calculated attribute RowStatusTrans.
         * @return the RowStatusTrans
         */
        public Integer getRowStatusTrans() {
            /*here row is reference variable of collection, this expression returns an int value if it is
             2-Modified
             0-New
             1-Unmodified
            -1-Initialized
            */
            byte entityState = this.getEntity(0).getEntityState();
            return new Integer(entityState);
        }
    

  • Have created a method to remove newly added row , and to undo changes in existing rows of departments VO in Impl class

  •     /**Method to revert changes of current row
         * @param curRow
         */
        public void revertChangesCurrentRow(Row curRow) {
            if (curRow != null) {
                curRow.refresh(Row.REFRESH_UNDO_CHANGES | Row.REFRESH_WITH_DB_FORGET_CHANGES);
            }
        }
    
        /**Method to check whether row should be removed or not 
         * If it is new - removed
         * If old one- Undo Changes
         * */
        public void revertOrremoveRowValues() {
            ViewObject deptVo = this;
            RowSetIterator deptIter = deptVo.createRowSetIterator(null);
            while (deptIter.hasNext()) {
                Row nextRow = deptIter.next();
                if (nextRow.getAttribute("RowStatusTrans") != null) {
                    Integer rowStatus = (Integer) nextRow.getAttribute("RowStatusTrans");
                    if (rowStatus == 2) {
                        System.out.println("Modified Rows-" + nextRow.getAttribute("DepartmentId"));
                        revertChangesCurrentRow(nextRow);
                    } else if (rowStatus == 0) {
                        System.out.println("New Row Removed");
                        nextRow.remove();
                    }
                }
            }
            this.executeQuery();
        }
    

  • To read more about REFRESH_UNDO_CHANGES and other constants -http://docs.oracle.com/cd/B14099_19/web.1012/b14022/oracle/jbo/Row.html
  • Exposed this method to client and added it to page bindings then called it on Partial Rollback button


  • After running application, i have changed some rows of Departments table and created a new row in employees table


  • Now if i use rollback, it will also remove the new row of employees table, this is the dis-advantage of using rollback


  • Again i have changed some rows of departments table and created a new row in employees table


  • Now see when i click on partial rollback button, it will only undo changes done in department table and employee table is untouched


  • And to stay on current row after partial rollback operation just remove executeQuery from revertOrremoveRowValues() method
Download Sample App
Cheers :-)  Happy Learning