How to Create OAF Insert/Update/Delete Page in R12.2.6
How to Create OAF Insert/Update/Delete Page
In this exercise we will create a OAF Page with Search , Insert ,Update and Delete Operations on the same page.
For this we will create a custom table under APPS Schema to perform this task.
CREATE TABLE apps.xxdcb_employee
(
employee_id NUMBER,
first_name VARCHAR2 (240),
last_name VARCHAR2 (240),
full_name VARCHAR2 (2000),
start_date DATE,
salary NUMBER,
position VARCHAR2 (240),
manager_name VARCHAR2 (240),
created_by NUMBER,
creation_Date DATE,
last_update_login NUMBER,
last_update_date DATE,
last_updated_by NUMBER
);
Step 1: Create a New Work space and Project
Step 2: Create a New Entity Object
Right click on Current Work space -> Business Tier -> Entity Object
Select the Table created earlier .Make sure Package is under server.schema as shown below
Since Primary Key does not Exists in table ,Wizard will Generate a ROWID By default.
Step 3: Create a New View Object (VO)
Generate VO from the EO Generated above.make sure you generate VOImpl and VORowImpl
Once finished Step 2 , 3 final One will look line the below in the Application Navigator
Step 4: Attach View Object (VO) to Application Module (AM)
Set below Property to AM since this AM we will be using for Insert,Update ,Delete operations also.
Right click on SearchAppAM -> Edit SearchAppAM -> Custom Properties
Name RETENTION_LEVEL
Value MANAGE_STATE
Step 5: Create a New OA Page
Set the below properties for the page.
ID
|
PageLayoutRN
|
Region Style
|
pageLayout
|
AM Definition
|
xxdcb.oracle.apps.fnd.server.SearchAppAM
|
Window
|
Employee Search Page
|
Title
|
Employee Search Page
|
Step 6: Create a New Query Region
ID
|
QueryRN
|
Region Style
|
query
|
Construction Mode
|
resultBasedSearch
|
Step 7: Create a New table (Query) Region
Select QueryRN created above and right click and select Region using Wizard.Select the AM and the VO available under the AM
Change Style of all Beans to "messageStyledText". Since it is a read only search page.
Step 8: To make Columns available for search.select the Bean and set "Search Allowed" and "Selective Search" Property to true.
Step 9: Save all your work and Run EmpSearchPG.xml
Step 10: Create a Region & Button for Insert Action
Select EmpSearchPG.xml , Right Click on PageLayoutRN -> New -> Region
ID
|
pageButtonBar
|
Region Style
|
pageButtonBar
|
Step 11: Create a Create Record Button in the button bar created above.
Right Click on PageButtonBar-> New -> Item
ID
|
Create
|
Region Style
|
submitButton
|
Construction Mode
|
/oracle/apps/fnd/attributesets/Buttons/Create
|
Step 12 : Create a New Page for Insert Operation
Name InsertPG
Package xxdcb.oracle.apps.fnd.webui
Set the below properties for the page.
ID
|
PageLayoutRN
|
Region Style
|
pageLayout
|
AM Definition
|
xxdcb.oracle.apps.fnd.server.SearchAppAM
|
Window
|
Create Employee
|
Title
|
Create Employee
|
Step 13 : Create a New Message Component Region under PageLayout Region
Repeat step 13 to create
EmployeeId
LastName
FirstName
Salary
StartDate
Position
Manager Name
Step 15: Create a New Button Bar Region and Insert Action Buttons
Right click on PageLayoutRN -> New -> Region
ID InsertPageButtonsRN
Region Style pageButtonBar
Create Apply and Cancel Buttons for Insert Record Page
Right click on InsertPageButtonsRN -> New -> Item
ID
|
Create
|
Region Style
|
submitButton
|
Construction Mode
|
/oracle/apps/fnd/attributesets/Buttons/Create
|
ID
|
Cancel
|
Region Style
|
submitButton
|
Construction Mode
|
/oracle/apps/fnd/attributesets/Buttons/Cancel
|
Step 16: Create a New Controller for Insert Page
Right click on PageLayoutRN -> Set New Controller
Package Name xxdcb.oracle.apps.fnd.webui
Class Name InsertEmployeeCO
Step 17: Add the following code under SearchAppAMImpl.java file
public void apply(){
getOADBTransaction().commit();
}
public void rollback(){
getOADBTransaction().rollback();
}
public void createRecord()
{
OAViewObject vo = getXxdcbEmployeeEVO();
if (!vo.isPreparedForExecution())
{
vo.executeQuery();
}
Row row = vo.createRow();
vo.insertRow(row);
row.setNewRowState(Row.STATUS_INITIALIZED);
}
Step 18: Add the below code in EmployeeSearchCO.java under processFormRequest method.
if (pageContext.getParameter("Create") != null)
{
pageContext.forwardImmediately(
"OA.jsp?page=/xxdcb/oracle/apps/fnd/webui/InsertPG",
null, OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
Step 18: Add the below code in InsertEmployeeCO.java
package xxdcb.oracle.apps.fnd.webui;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
/**
* Controller for ...
*/
public class InsertEmployeeCO extends OAControllerImpl
{
public static final String RCS_ID="$Header$";
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
am.invokeMethod("createRecord", null);
}
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
// Pressing the "Apply" button means the transaction should be
// validated and committed.
if (pageContext.getParameter("Create") != null)
{
OAException message = new OAException("Record has been Inserted!", OAException.INFORMATION);
pageContext.putDialogMessage(message);
am.invokeMethod("apply");
pageContext.forwardImmediately(
"OA.jsp?page=/xxdcb/oracle/apps/fnd/webui/EmpSearchPG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
true, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
else if (pageContext.getParameter("Cancel") != null)
{
am.invokeMethod("rollback");
pageContext.forwardImmediately("OA.jsp?page=/xxdcb/oracle/apps/fnd/webui/EmpSearchPG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
false, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
}
}
Step 21: Create a New Items for Update,Delete Action
Right click on SearchResultsTable(XxdcbEmployeeEVO)-> New -> Item
Attribute
|
Property
|
|
ID
|
Update
|
|
Item Style
|
image
|
|
Atribute Set
|
/oracle/apps/fnd/attributesets/Buttons/Update
|
|
Prompt
|
Update
|
|
Image URI
|
updateicon_enabled.gif
|
|
Action Type
|
fireAction
|
|
Event
|
update
|
|
Submit
|
TRUE
|
|
Parameters
|
Name
|
Value
|
empId
|
${oa.XxdcbEmployeeEVO.EmployeeId}
|
Attribute
|
Property
| |
ID
|
Delete
| |
Item Style
|
image
| |
Atribute Set
|
/oracle/apps/fnd/attributesets/Buttons/Delete
| |
Prompt
| Delete | |
Image URI
|
deleteicon_enabled.gif
| |
Action Type
|
fireAction
| |
Event
|
delete
| |
Submit
|
TRUE
| |
Parameters
|
Name
|
Value
|
empId
|
${oa.XxdcbEmployeeEVO.EmployeeId}
|
Step 22: Create a New Page for Update Action and update the following properties
Right click on CurrentProj-> New -> Web Tier -> OA Components -> Page
ID
|
PageLayoutRN
|
Region Style
|
pageLayout
|
AM Definition
|
xxdcb.oracle.apps.fnd.server.SearchAppAM
|
Window
|
Update Page Windows
|
Title
|
Update Page
|
Step 22: Add the Beans to the MainRN similar way how we created Insert page as shown below
Step 23: Set New Controller to the update Page .
Step 24: Add the following code under SearchAppAMImpl.java file
public void initUpdateRow(String empId)
{
OAViewObject vo = getXxdcbEmployeeEVO();
vo.setWhereClause("employee_id = :1");
vo.setWhereClauseParams(null); // Always reset
vo.setWhereClauseParam(0, Integer.parseInt(empId));
vo.executeQuery();
}
Step 25: Add the following code under UpdateCO.java file
package xxdcb.oracle.apps.fnd.webui;
import java.io.Serializable;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.webui.OAControllerImpl;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
/**
* Controller for ...
*/
public class UpdateCO extends OAControllerImpl
{
public static final String RCS_ID="$Header$";
public static final boolean RCS_ID_RECORDED =
VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
/**
* Layout and page setup logic for a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
String employeeId = pageContext.getParameter("empid");
Serializable[] params = { employeeId};
am.invokeMethod("initUpdateRow", params);
}
/**
* Procedure to handle form submissions for form elements in
* a region.
* @param pageContext the current OA page context
* @param webBean the web bean corresponding to the region
*/
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
OAApplicationModule am = pageContext.getApplicationModule(webBean);
if (pageContext.getParameter("Update") != null)
{
am.invokeMethod("apply");
pageContext.forwardImmediately("OA.jsp?page=/xxdcb/oracle/apps/fnd/webui/EmpSearchPG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
false, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
else if (pageContext.getParameter("Cancel") != null)
{
am.invokeMethod("rollback");
pageContext.forwardImmediately("OA.jsp?page=/xxdcb/oracle/apps/fnd/webui/EmpSearchPG",
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
null,
false, // retain AM
OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
}
}
}
Step 26: Run the EmpSearchPG and check is the update is working as expected.
Step 27: Add the below code in the SearchAppAMImpl.java for the Delete operation
public void deleteRecord(String employeeId)
{
OAViewObject vo = getXxdcbEmployeeEVO();
XxdcbEmployeeEVORowImpl row = null;
int fetchedRowCount = vo.getFetchedRowCount();
RowSetIterator deleteIter = vo.createRowSetIterator("deleteIter");
if (fetchedRowCount > 0)
{ deleteIter.setRangeStart(0);
deleteIter.setRangeSize(fetchedRowCount);
System.out.println("employeeId"+employeeId);
for (int i = 0; i < fetchedRowCount; i++)
{
row = (XxdcbEmployeeEVORowImpl)deleteIter.getRowAtRangeIndex(i);
if(row.getEmployeeId().intValue()==Integer.parseInt(employeeId)){
row.remove();
getTransaction().commit();
break;
}
}
}
deleteIter.closeRowSetIterator();
}
Step 28: Add the below code in the EmployeeSearchCO in ProcessformRequest Method
if ("delete".equals(pageContext.getParameter(EVENT_PARAM)))
{
String rowRef = pageContext.getParameter(OAWebBeanConstants.EVENT_SOURCE_ROW_REFERENCE);
OARow row = (OARow)am.findRowByRef(rowRef);
employeeId = row.getAttribute("EmployeeId");
OAException message = new OAException("Are you sure you want to delete this row?",OAException.WARNING);
OADialogPage dialogPage = new OADialogPage(OAException.WARNING, message, null, "", "");
String yes = pageContext.getMessage("AK", "FWK_TBX_T_YES", null);
String no = pageContext.getMessage("AK", "FWK_TBX_T_NO", null);
dialogPage.setOkButtonItemName("DeleteYesButton");
dialogPage.setOkButtonToPost(true);
dialogPage.setNoButtonToPost(true);
dialogPage.setPostToCallingPage(true);
dialogPage.setOkButtonLabel(yes);
dialogPage.setNoButtonLabel(no);
pageContext.redirectToDialogPage(dialogPage);
}
else if (pageContext.getParameter("DeleteYesButton") != null)
{
Serializable[] parameters = { employeeId.toString() };
am.invokeMethod("deleteRecord", parameters);
OAException confirmation = new OAException("Record deleted Successfully", OAException.CONFIRMATION);
pageContext.putDialogMessage(confirmation);
}
Step 29: Save all the changes and run the EmpSearchPG to test delete functionality.
Congratulations, you have done it. we have build a Simple Search,Insert,Update, Delete Page a Fully functional Page.!
Please comment if you want the source code for this project will share it via google drive.
I want source code
ReplyDelete