Saturday, February 2, 2013

Create a row at the end of an ADF table

Okay, so the user will select a department name, and based on that, employees will be displayed. The user will click on Create button post which a blank row will be inserted where the user will have to enter valid values, and after that click on Commit to save data in database.

Okay. Some things to remember. Set the PartialSubmit property of the button to be True and the PartialTrigger of the table to be set as the ID of the button. This is the code that is executed when the user presses Create button.

import oracle.adf.model.BindingContext;
import oracle.binding.BindingContainer;
import oracle.jbo.NavigatableRowIterator;
import oracle.jbo.Row;
import oracle.jbo.uicli.binding.JUCtrlHierBinding;
import oracle.adf.model.binding.DCIteratorBinding;

    public String cb1_action() {
        // Add event code here...
        BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
        JUCtrlHierBinding hierBinding = (JUCtrlHierBinding)bc.get("EmployeesView3");
        DCIteratorBinding dciter = hierBinding.getDCIteratorBinding();
        NavigatableRowIterator nav = dciter.getNavigatableRowIterator();
        Row newRow = nav.createRow();
        Row lastRow = nav.last();
        int lastRowIndex = nav.getRangeIndexOf(lastRow);
        nav.insertRowAtRangeIndex(lastRowIndex + 1, newRow);
        return null;
Now some concepts about inserting row in different places of the table:

1. User wants to create a new row as the first row of the table. In that case

nav.insertRowAtRangeIndex(0, newRow);
2. User wants to create a new row before the current selected row

3. User wants to create a new row after the current selected row

Row currentRow = nav.getCurrentRow();
int currentRowIndex = nav.getRangeIndexOf(currentRow);
nav.insertRowAtRangeIndex(currentRowIndex+1, newRow);
Infact if the CreateInsert operation is dragged into the page and created as a button, the 2nd point would have been achieved.

If you set the EditingMode as 'clickToEdit', the rows will appear as read-only. Once the user clicks on a particular row, he/she can edit the row. But make sure that the row selection of the table component must be set as Single.

Difference between AutoSubmit and PartialSubmit
autoSubmit: Related to an input component (such as inputText and selectOneChoice) or a table select component (such as tableSelectOne). The component automatically submits the form it is enclosed in
partialSubmit: Releated to a command component. The page partially submits when the button or link is clicked.

If a component has its immediate attribute set to true, then the validation, conversion, and events associated with the component are processed during this phase.

This method should be used to create a row and then to mark it temporary (STATUS_INITIALIZED) so that the user can use the created Row to fill UIs like Table UIs with valid default values for rows. Then when the Row values are updated, UIs should once again call this method to turn the Row into new (STATUS_NEW) state before any setAttribute calls on the Row, so that the changes are validated and posted.

Download the sample application from File Cabinet: CreateEmployee.rar


  1. Hi
    I need the sample code if it is possible.


  2. This comment has been removed by the author.

  3. This comment has been removed by the author.