Saturday, 29 August 2015

Programatically add record to database in ADF

Requirement: I have a addProgDemo.jsf page. In that page I have three af:inputText and one af:button. Just for alignment purpose I have surrounded all three af:inputText and af:button inside a af:panelFormLayout.
The labels for the three af:inputText are: Country Id, Country Name, and Region Id, and the text for the af:button is Save. Now I will enter values in all these three af:inputText  and then click the Save button. On click of Save button it should save the values in the Oracle database table.
Note: I have to achieve this functionality programmatically.

Solution: We will use the COUNTRIES table of Oracle database XE present in the HR schema. For solution of the above requirement follow the below steps:
 
Step 1: Create an Oracle ADF Fusion Web Application.

Step 2: Create an ADF Business Components from tables.The ADF Business Components should contain: AppModule, CountriesEO, and CountriesVO as shown below:

Step 3: Create a addProgDemo.jsf page in the ViewController project of our application created in Step 1. Drag and drop af:panelFormLayout. Now drag and drop three af:inputText and one af:button inside the af:panelFormLayout. Give the label names for the three af:inputText as Country Id, Country Name, and Region Id respectively. Also create the bindings for all these three af:inputText. Give the text name of the af:button as Save. Create an actionListener for this button. The detailed code for the addProgDemo.jsf page is shown below:

Step 4: Go to the binding tab of the addProgDemo.jsf page and create the Binding and Executables as shown below: 

Step 5: Write the below codes in MyBean.java.


Step 6: Save all and run the application. The ran application is shown below:
Step 7: Now we will enter values in the UI for Country Id, Country Name and Region Id as BN, Bangladesh, and 3 respectively. Before that I will verify that there is no record with Country Id as BN. To verify write the below query:


Now enter the above values in the addProgDemo.jsf and click on Save. Thus, the data get saved in the database.
Hence, the solution to the above requirement.


Thanks & Regards,
Susanto Paul