Saturday, 30 September 2017

Set default values to attributes in the EntityObject for every insert in Oracle ADF

Requirement: Here in this post, we will be demonstrating the case where we will be setting default values to the attributes in the EntityObject for every new insert in Oracle ADF.
For demonstration purpose we will be using the Employees table present in the HR Schema of the Oracle Database XE 11g.
For solution of the above requirement follow the steps as shown below:
Step 1: Create an Oracle ADF Fusion Web Application named as DefaultValueInEO.
Step 2: Create an ADF Business components from tables (EmployeesEO, EmployeesVO and AppModule) from the Employees table. Click on the EmployeesEO to open EmployeeEO.xml in the editor window à Click Java à Check Generate Entity Object Class: EmployeesEOImpl à Check Accessors àCheck Create Method àClick OK as shown below.
Step 3: Open EmployeesEOImpl.java and edit the create method as shown below.
Here we have set the default values for the LastName, Email, and PhoneNumber as Paul, susanto@abc.com, and 7878787878 respectively.
Also, we can set the default value to the attribute by following the below steps. Click on the EmployeesEO to open EmployeeEO.xml in the editor window à Click Attributes à Click DepartmentId à Open Details tab à Set Default Value (Select Literal) to 20 (This will set the default value of the DepartmentId to 20).
Step 4: Create a demo.jspx page. Drag and drop EmployeesVO1 as an ADF Form from the Data Control. Also Drag and Drop CreateInsert (available under AppModuleDataControl à EmployeesVO1 à Operations à CreateInsert) as an ADF Button, and Commit (available under AppModuleDataControl à Operations à Commit) as an ADF Button.
Thus, the complete demo.jspx UI will look as below.
Save All and Run the application. Thus, the ran application is shown below.
Click on CreateInsert button, which will prepare the form available for new Insert.
In the below form we can see that the default values for the LastName, Email, and PhoneNumber as Paul, susanto@abc.com, and 7878787878 respectively. These values are set from the EmployeesEOImpl.java class.
Also DepartmentId is having default value as 20 which is set dynamically.
Fill the above form and click on Commit button to Save the changes in the Database.
Just to verify we will query in the database to check if the record is inserted successfully.
Hence, the solution to our requirement.
If you like the post, please comment, share the post and do like me on Facebook.

Thanks & Regards,
Susanto Paul