Wednesday, July 18, 2012

ValidateEntity, NewRowState and Commit


Below is stated from Developer's Guide:

 

Entity Object Initial / New State

By default, entity objects are created with the row state of STATUS_NEW, and BC4J adds them to its validation and post listener lists. In this case, any event that triggers a validation or database post sequence includes these entity objects.

As stated in the OA Framework Model Coding Standards, always circumvent this behavior by explicitly calling the setNewRowState(STATUS_INITIALIZED) method on its containing ViewRowImpl immediately after you insert the newly created row. This sets the state of any associated entity objects to STATUS_INITIALIZED.

When you do this, BC4J removes the corresponding entity objects from the transaction and validation listener lists, so they will not be validated or posted to the database. As soon as the user makes a change (an attribute "setter" is called), the entity object's state changes to STATUS_NEW, and BC4J returns it to the validation/post lists. You can also call setNewRowState(STATUS_NEW) on the ViewRowImpl to change the state manually at any time.

Code Behaviour:

Case 1: Row has been modified in the UI before submit. Row State could be anything. 
  • The RowState becomes New.
  • ValidateEntity will get called before processFormRequest().
Case 2: Called row.setNewRowState(Row.STATUS_NEW) after inserting a new row. Row has not been modified from UI.
ValidateEntity will not get called before processFormRequest() but will get called on commit and postChanges.
Case 3: Called row.setNewRowState(Row.STATUS_INITIALISED) after inserting a new row. Row has not been modified from UI.
  • ValidateEntity will not get called before processFormRequest() or on commit or postChanges.
  • The Row will be ignored by the Framework and removed from the Cache.
  • Even the mandatory fields in the Entity Object are not checked.
Please note setting the row state (row.setNewRowState) should be done after adding the row to VO as recommended in the OAF Standard.

Though if you set the row state before adding it to the VO, it'll also work fine as long as you don't call any setter. The moment any setter is called row state changes to NEW.

No comments:

Post a Comment