Thursday, May 23, 2013

Adding records to View Objects at custom locations

if you are using a table component in your adf page you should have noticed by now that when you invoke the createInsert method of any view object then the new record will be added before the currently selected row.of course this may not be that big of an issue ; since you can sort the table using any column you want.
But you may have a use case where it's required to add the row after the current row, first or last row in table.

the following are the steps needed to achieve such goals:
  1. open the view object xml file in the overview mode and open the java tab.
  2. generate the ViewObjectImpl class.
  3. now you can either :
    • override the insert method of the view object .
    • add your own custom methods and expose them to the client.

if you want to override the insert method add the following in the overriding method body:
  • insert as the last row:
                  @Override
                   public void insertRow(Row row){
                        last();
                        next();
                        super.insertRow(row);
                   }
  • insert as the first row:
                  @Override
                   public void insertRow(Row row){
                        first();
                        super.insertRow(row);
                   }
  • insert as the following row:
                  @Override
                   public void insertRow(Row row){
                        next();
                        super.insertRow(row);
                   }
    then call the createInsert operation of the view object.

    or you can write your own custom code, similar to:
                      public void insertLast(){
                                last();
                               next();
                              Row r= createRow();
                              insertRow(r);
                     }
    then expose to the client and call it from the page.

      No comments:

      Post a Comment