Please disable your adblock and script blockers to view this page

Search this blog

Thursday, 25 October 2012

Set on Current row after Rollback Execute or page refresh

Some times we edit a table in form and Save(Commit & Execute) or Cancel(Rollback & Execute)  and table refreshed to its first record means focus is now on first row of table.
And we need the same row again, then we search it and perform another operation, this is really disgusting behavior of table for Developer.

To set on previously selected row after execute we can use this code,
in this scenario we have to get current row key from its IteratorBinding and after Execute we can set it again to show that row as selected.





    /**
     * Generic Method to call operation binding
     **/
     public BindingContainer getBindings() {
      return BindingContext.getCurrent().getCurrentBindingsEntry();
     }


     BindingContainer bindings = getBindings();
     //Get Iterator of table
     DCIteratorBinding parentIter = (DCIteratorBinding)bindings.get("IteratorName");
     //Get current row key
     Key parentKey = parentIter.getCurrentRow().getKey();

     //You can add your operation code here, i have used simple Cancel operation 
     //with Rollback and Execute
     
     
     OperationBinding ob= bindings.getOperationBinding("Rollback");
     ob.execute();
     OperationBinding ob1= bindings.getOperationBinding("Execute");
     ob1.execute();
    
     //Set again row key as current row
     parentIter.setCurrentRowWithKey(parentKey.toStringFormat(true));


17 comments :

  1. Hello Ashish:

    Can you please detail the code with the import statements as well? I am using 11.1.2

    I could not get the code working.

    Thanks
    Krishna

    ReplyDelete
    Replies
    1. Use these import statement-

      import oracle.adf.model.binding.DCIteratorBinding;
      import oracle.binding.BindingContainer;
      import oracle.binding.OperationBinding;
      import oracle.jbo.Key;


      I think it should work fine now

      Delete
    2. Thank you for the reply and also to the blog post.
      I am using ADF form to display data. I get null pointer exception for getCurrentRow(). Should I be using table control?

      Delete
  2. Are you using only form? or both table and form. (Use table and form both)
    and Ensure that you have written Iterator Name(Table Iterator) same as in binding of page is given.

    ReplyDelete
    Replies
    1. hello Ashish;
      Iam using database view as adf table it will work.Can you tell where to place this code.It is a java code i am new to adf.
      soodesh

      Delete
  3. Hi Ashish,

    I have a read-only view object and has a primary key on it.

    I have a table and formlayout on my page.

    I can set selected row key to parent key after commit and execute and i can see details of this row on my form layout.

    But in my table, this row disappears.

    Is there a way to avoid it?

    Thanks in advance!

    Best Regards,
    Murat

    ReplyDelete
    Replies
    1. I just realized the row doesn't disappear.

      its row number is changed to 26.

      Even the iterator has sor order by primary key, it doesnt sort rows accordingly sort criteria.

      My edited row goes to 26. row in my table.

      Is there a way to see the row where it was before commit and execute?

      Thank you

      Delete
    2. It is not a problem , after commit due to order by row will appear as per the clause

      Delete
    3. But in this way, user will need to order by row manually at all time, right?

      Delete
    4. User has already changed row values and committed data then why he/she need to navigate to that row again ?
      Still you can try Jump to specific row in ADF Table

      Ashish

      Delete
    5. We have interesting customers :D
      Anyway many thanks Ashish.
      You rock as always

      Delete
  4. where should i put this code

    ReplyDelete
    Replies
    1. You can use this code in managed bean where you need to set current row after execute of table or viewObject

      Delete
  5. Awesome post. Was able to fix the issue with ease

    ReplyDelete