Say that you want to develop an interactive screen that inputs data, processes it and then produces an output. This involves talking to database. So far we have done a lot of searching through OAF screens by inputting data into text fields. But hey, what if you want to commit those values on to database? Right from the same OAF screen? Yes! It can be done using the steps given below. Happy coding!
Requirement: To insert record into table from OAF screen
Step 1: Create a new OA workspace and OA project
Create a OA workspace with file name as: InsertRecord
Create a OA project with file name as: InsertRecord
Default package: oaf.oracle.apps.fnd.insertrecord
Once your project is created, double click on Poplist project and select Project content.
Click on 'Add' button next to the bottom pane in the Project content and select only that package which you want have in your project.
Click OK and save your project.
Step 2: Create a ADF Business component - Application Module AM
Right click on InsertRecord project -> click New -> select ADF Business components -> select Application Module
Package: oaf.oracle.apps.fnd.insertrecord.server
AM Name: InsertRecordAM
Check Application Module Class: InsertRecordAMImpl Generate Java File(s)
Once the AM is created, double click on the AM just created and in the window that opens select Custom Properties and set the values as below, click on Apply and then Ok.
Step 3: Create a OA Components page
Right click on InsertRecord project -> click New -> select OA components under Web Tier -> select Page
Package: oaf.oracle.apps.fnd.insertrecord.webui
Page Name: InsertRecordPG
Step 4: Set Page properties
Select on the InsertRecordPG page and go to structure pane where a region of type 'pageLayout' and ID 'region1' is automatically created.
Click on region1 in structure page and set the project properties as in the below screenshot - set all the properties except the controller class, for now.
Step 5: Set new Controller
Select PageLayoutRN in the structure pane -> Right click on it -> Set new controller
Package: oaf.oracle.apps.fnd.insertrecord.webui
Controller name: InsertRecordCO
This automatically sets the controller class property in InsertRecordPG page properties.
Step 6: Create a table to insert values
CREATE TABLE insertrecord
(
column1 VARCHAR2(100),
column2 VARCHAR2(100),
-- ---------------------
-- Who Columns
-- ---------------------
last_update_date DATE NOT NULL,
last_updated_by NUMBER NOT NULL,
creation_date DATE NOT NULL,
created_by NUMBER NOT NULL,
last_update_login NUMBER
);
Step 7: Create a ADF Business component - Entity Object
Right click on InsertRecord project -> New -> ADF Business Components -> Entity Object
Name -> InsertRecordEO
Package: oaf.oracle.apps.fnd.insertrecord.schema.server
Database Object: INSERTRECORD
ROWID will be the default primary key if the table has no primary key. Check the Accessors, Create Method, Validation Method and Remove Method.
Step 8: Create a ADF Business component - View Object
Right click on Poplist project -> click New -> select ADF Business components -> select View Object
Package: oaf.oracle.apps.fnd.insertrecord.server
VO Name: InsertRecordVO
In the Step 2, select InsertRecordEO and shuttle them to selected list
In Step3, from the Attributes window select columns Column1, Column2 and shuttle them to selected list.
In step-8(Java) of VO creation uncheck all the pre-selected checkboxes and select View Row Class: ViewObjRowImpl -> Generate Java File -> Accessors check box Accept all other defaults in VO creation, click Finish to create the VO under the package specified.
Step 9: Attach VO to AM
After creating VO successfully, we must associate this VO with AM we have created
Right click on InsertRecordAM -> Edit InsertRecordAM
Select 'Data Model' on the window that pops up
You should find InsertRecordVO listed in the left panel, Shuttle the InsertRecordVO to the right pane to associate it with the InsertRecordAM which is displayed as InsertRecordVO1 as in the below screenshot
Click on Apply and OK to save the changes made to InsertRecordAM
Step 10: Create layout in InsertRecordPG
Right click on PageLayoutRN -> New -> Region
Now, this creates a new region of style header under PageLayoutRN
Select region1 - set the ID as MainRN and set the region style to defaultSingleColumn
Step 11: Create items in MainRN
Right click on MainRN > New > Item
Create one more item in a similar way.
Set the properties of both the screenshots as in the below screenshots:
Step 12: Add Apply and Cancel buttons
Right click on PageLayoutRN > New > Region
ID -> Buttons
Region Style -> pageButtonBar
Right click on Buttons -> New -> Item
Attribute Set -> /oracle/apps/fnd/attributesets/Buttons/Cancel
Enter the properties for the item as in the below Screenshot
Similarly create one more item for Cancel button
Attribute Set -> /oracle/apps/fnd/attributesets/Buttons/Cancel
Enter the properties for the item as in the below Screenshot
Step 13: Code to Insert Record
Put the following code in InsertRecordAMImpl.java
public void createRecord()
{
OAViewObject vo = (OAViewObject)getInsertRecordVO1();
if (!vo.isPreparedForExecution())
{
vo.executeQuery();
}
Row row = vo.createRow();
vo.insertRow(row);
row.setNewRowState(Row.STATUS_INITIALIZED);
}
public void apply()
{
getTransaction().commit();
}
Step 9: Code to capture button click
Capture the button click event in CO to insert record to table.
Add the code in the following Process Request and Process Form Request Functions in your CO as in the below screenshots
PR:
if (!pageContext.isFormSubmission())
{
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.invokeMethod("createRecord", null);
}
PFR:
OAApplicationModule am = pageContext.getApplicationModule(webBean);
// Pressing the "Apply" button means the transaction should be
// validated and committed.
if (pageContext.getParameter("Apply") != null)
{
OAViewObject vo = (OAViewObject)am.findViewObject("InsertRecordVO1");
String column1 = (String)vo.getCurrentRow().getAttribute("Column1");
String column2 = (String)vo.getCurrentRow().getAttribute("Column2");
OAException message = new OAException("Record has been Inserted!", OAException.INFORMATION);
pageContext.putDialogMessage(message);
am.invokeMethod("apply");
pageContext.forwardImmediately(
"OA.jsp?page=/oaf/oracle/apps/fnd/insertrecord/webui/InsertRecordPG",
null, OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
if (pageContext.getParameter("Cancel") != null){
pageContext.forwardImmediately(
"OA.jsp?page=/oaf/oracle/apps/fnd/insertrecord/webui/InsertRecordPG",
null, OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
Result:
On page load:
Input data to be inserted:
On Insert record:
Verification:
Before Insertion:
After Insertion:
Comments
RSS feed for comments to this post