Sunday, 30 March 2014

Oracle ADF “Create Insert” into read only table


The following related to Jdeveloper 11g (

Sometimes you want to present the data in the table as read-only, but still provide an option to create a new record by using build-in “create insert” functionality. Obviously we need some king of mechanism to make existing records “read-only” and new record to be “editable”.

Lacily for us  where is a property in Entity Object attribute called updatable. You can set its value to “While New” . So it will not be updatable all the time except when you are trying to create a new record.

But many times this is completely useless feature.

Consider the following table

create table xx_adf_demo (key_column number,customer_id number) 


I can define customer_id  “While New” , but it doesn’t give me anything since end-user is not interested to see the customer id , but customer name. So I need to join “xx_adf_demo” with some other table/view that holds the “customer_name”.

So my View Object will not be based only on the Entity Object , but also on some other table.

The good new I can see now the customer name. The bad news  - this field is not based on the Entity Object and there is no “While New” option in View Object attributes. For now we will just set it to “Always”

Here is the solution.

I will start by defining the sequence for “key_col” attribute and setting it into default value for this column.

create sequence xx_adf_demo_s
minvalue 1
maxvalue 9999999999999999999999999999
start with 115
increment by 1
cache 20;


we will also define a new transient attribute called “isReadOnly” of Boolean type and “Updated” Always


Generate View Object Row java class and modify the “getisReadOnly” function

if (getEntityForAttribute("TagId").getEntityState() == EntityImpl.STATUS_NEW)
                      return Boolean.FALSE;
                      return Boolean.TRUE;


By using this code “isReadOnly” flag will be automatically set for “false” when row state is new.

Create another View Object to hold the LOV for customer name and assign it to customer name attribute in XxAdfDemoVO View Object.


Now create you GIU by dragging the View Object, Create Insert, Commit and Rollback Buttons to the page (Place the buttons in the Panel Collection toolbar). When you dragging the View Object to the page – choose to drop it as “Adf Table…”



If we run it now as is we will get


We see that “customer name” column is not read only. Also note the value of “isReadOnly” column

Only small modification needed to achieve what we need. Modify “Read Only” property of “CustomerName” LOV to be #{row.isReadOnly}.


Save and refresh the page. Click on the “CreateInsert”.



We are done.

You can download the workspace from this link

No comments:

Post a Comment