Saturday, December 26, 2015

Very Practical CRUD with JET and ADF BC - PATCH Method

I'm going to share few more tips, how to implement CRUD in JET and call ADF BC 12.2.1 REST service. You are going to learn how to implement table row selection and how to call REST PATCH method to update data through ADF BC REST service. Why very practical? You can take sample application code and use it in your project. Less theory and more practical hints - this is my approach.

This is how it looks JET table (with pagination control - Oracle JET Collection Paging Control and ADF BC REST Pagination Perfect Combination) and form. Download sample application - User can select row and edit data in the form:

I'm going to change salary value for Alexander Hunold and invoke PATCH method with Update button click:

Through network monitor in NetBeans we can check REST method execution. PATCH method is executed for employee ID 103 with Content-Type set to Oracle ADF resource item:

Changed salary value is submitted through Request Data:

We should check ADF BC log. It shows executed SQL statement to update employee salary by employee ID. This works as expected:

Table row selection in JET is implemented with selection mode property:

ADF BC 12.2.1 REST service access in JET is easy. You need to define collection (set URL, fetchSize and model). In case of pagination, you should wrap table data source with paging data source type:

When collection is set with Fetch Size (collection is virtualized), there is a special way to access rows from the collection. Row retrieved by key from the collection, will be returned with Promise type. You should use then function to retrieve row value. This is how selected row data is retrieved. Next step is to update form fields to display selected row data, this is done through updatFields method:

Method updateFields sets each element from the form with values from selected row attributes:

Initially form elements are defined as observables with empty values:

In HTML each form field is mapped through data-bind property with  corresponding element defined in Java Script - this is how it's all mapped together:

Update button handles click event and calls update method:

Row data is updated through REST service with PATCH method, initialized by save operation on current row. Row to be updated is assigned with attribute values from form fields. PATCH method is configured through save operation property, you must do it explicitly. By default, PUT method will be executed, which requires to submit all attributes for the row, otherwise ADF BC will throw error. PATCH method is much better, there is no need to submit values for all attributes from EO row:

In my next posts, I'm going to cover create/delete, validations and call failure cases.


gareth said...


When you are using the Jet with Rest,
1. is it always a best practice to only use one REST service url?

When you have REST web service, that is not just as simple as CRUD. Let us say, it also invokes SOA services in the backend or BPM,

2. is it still possible to use the ojmodel?
3. The use case has different REST web service calls creating records (which access SOA\BPM), for delete, etc. I am just confused why do we have also idAttr in the ojmodel.

gareth said...

also, if you have a form and you need to make it readonly after saving, do you declaratively set the readonly to a flag like in ADF?

Andrejus Baranovskis said...

Good points. I will try to answer these questions in next posts.