Oct 12, 2012

create a new row in ADF

The 3 different create operations provided by ADF:-
1.)Create:-
This operation opens a slot for a new record in the collection. The new record is added to the collection after the page is submitted.Therefore, if the user abandons the page by navigating away, an empty record is not left orphaned.The new record opened by Create is inserted before the current record in the iterator.

A create operation in the pageDef does the following:
// create a new row for the view object
Row newRow =  viewObject.createRow();
// mark the row as being "initialized", but not yet new
newRow.setNewRowState(Row.STATUS_INITIALIZED);


When we call create and set the status, my adf faces page disables all fields (as if the iterator does not point to the newly created row).

After clicking on Create Button no new row is created in table.








2.)CreateInsert:-
 This operation is the same as Create, except that the new empty record is inserted into the collection as part of the operation.This means that even if the user never submits the page, the row will still be in the collection.

 In addition, if you are using the CreateInsert operation, it performs the additional line of code to insert the row into the row set:
// insert the new row into the view object's default rowset
yourViewObject.insertRow(newRow);

When I call createInsert, my adf faces page reflects the current row as an empty form, when the values are filled out it is commited properly.

 After clicking on CreateInsert Button a new empty row is created.










Note:-Create and CreateInsert, can be a little confusing because they seem to accomplish the same task. The row created by the Create operation is managed as a temporary object by the framework. If the user abandons an
input screen without submitting the new record, the row will simply disappear, leaving the programmer with no clean-up to do. CreateInsert, however, requires clean-up. Although the Create behavior is generally more useful, there are still some circumstances where CreateInsert should be used. Typically, this will be when the side effects of entity object creation are desirable. For example, the create method on the entity object adds information defined as defaults for attributes such as dates and reference numbers. With CreateInsert, this
default information will be visible to the user on the created (blank) record. If the Create operation is used, the defaults will not be set until after the user submits the new record.

3.)CreateWithParams:-
This operation is same as CreateInsert and only difference is that we can assign default values on CreateInsert.

CreateWithParams operation allows us to define parameter to assign it to the new row for some specific attribute.

After clicking on  CreateWithParams button a new row with defalult value of JobId created.










Note:-The ADF BC data control exposes three operations for a view object to create a new row: Create, CreateInsert, and CreateWithParams. The Create operation creates a new row for the collection but doesn’t add it to the iterator. CreateInsert works the same as Create but adds the new row above the current row in the iterator. CreateWithParams works the same as CreateInsert but optionally allows developers to define default values declaratively for the row attributes. The difference between Create and CreateInsert is only relevant if the collection is displayed in a table, not for a form.

No comments:

Post a Comment