Search This Blog

Create a row at the end of an ADF table

 
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();
        newRow.setNewRowState(Row.STATUS_INITIALIZED);
        Row lastRow = nav.last();
        int lastRowIndex = nav.getRangeIndexOf(lastRow);
        nav.insertRowAtRangeIndex(lastRowIndex + 1, newRow);
        dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
        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

newRow.setNewRowState(Row.STATUS_INITIALIZED);
nav.insertRowAtRangeIndex(0, newRow);
dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
 
2. User wants to create a new row before the current selected row

newRow.setNewRowState(Row.STATUS_INITIALIZED);
nav.insertRow(newRow);
dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
 
3. User wants to create a new row after the current selected row

newRow.setNewRowState(Row.STATUS_INITIALIZED);
Row currentRow = nav.getCurrentRow();
int currentRowIndex = nav.getRangeIndexOf(currentRow);
nav.insertRowAtRangeIndex(currentRowIndex+1, newRow);
dciter.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
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.

setNewRowState
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.

No comments:

Post a Comment