Here we will learn about updating the data in OAF. Along with this we will also see the following:
- Redirect from one Page to another.
- Pass Parameters from one Page to another.
- SPEL
- Dynamically execute VO Query.
Let’s start.
- Right Click on ResultRN to add new column UpdateCol.
- Right Click on columnHeader to add header.
ID: UpdateColHdr
Prompt: Update - Right Click on UpdateCol to add an image item.
ID: Update
Item Style: image
Prompt: Update
Image URI: updateicon_enabled.gif - Attach fireaction to the image.
Action Type: fireAction
Event: EmpRecordUpdate
Parameters:Name Value XXRDEmpID ${oa.XXRDEmpVO1.EmpId} whatever we have defined under Parameters is called SPEL, Simplest Possible Expression Language. Here XXRDEmpID is any user defined variable. and the corresponding value is SPEL, the expression is ${oa.ViewInstance.ViewAttribute}. Ideally this value should be unique to recognize a particular record in database table. In our case Employee ID is Primary Key which is Unique as well.
- Now add new controller to the Search Page in order to write logic. Right click on MainRN > Set New Controller.Package Name: xxrd.oracle.apps.ap.webui
Class Name: XXRDSearchEmpCO - Write Logic as mentioned below:
In XXRDRootAMImpl:
// To update Employee Record
public void updateEmployee(String empID){
XXRDEmpVOImpl empVO = getXXRDEmpVO1();
System.out.println(“AM:empID=”+empID);
empVO.setWhereClause(null);
empVO.setWhereClause(“emp_id = “+empID);
empVO.executeQuery();
}In XXRDSearchEmpCO:
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
XXRDRootAMImpl rootAM = (XXRDRootAMImpl)pageContext.getApplicationModule(webBean);
String eventName = pageContext.getParameter(EVENT_PARAM);if(eventName!=null && eventName.equals(“EmpRecordUpdate”)){
if(pageContext.getParameter(“XXRDEmpID”)!=null){
String empID = pageContext.getParameter(“XXRDEmpID”);HashMap hm = new HashMap();
hm.put(“pageSource”,”SearchPG”);
hm.put(“XXRDEmpID”,empID);// Redirect to Create Page i.e. XXRDCreateEmpPG
pageContext.setForwardURL(“OA.jsp?page=xxrd/oracle/apps/ap/webui/XXRDCreateEmpPG”,
null,
OAWebBeanConstants.KEEP_MENU_CONTEXT,
null,
hm, // pass parameters using hashmap
true,
OAWebBeanConstants.ADD_BREAD_CRUMB_NO,
OAWebBeanConstants.IGNORE_MESSAGES
);
}
}
}In XXRDCreateEmpCO:
public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processRequest(pageContext, webBean);// Get access to AM attached at page level i.e Root AM
OAApplicationModuleImpl rootAM = (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);if(pageContext.getParameter(“pageSource”)!=null && pageContext.getParameter(“pageSource”).equals(“SearchPG”)){
if(pageContext.getParameter(“XXRDEmpID”)!=null){
String empID = pageContext.getParameter(“XXRDEmpID”);
System.out.println(“CO:empID=”+empID);
Serializable params[] = {empID};
Class classes[] = {empID.getClass()};
rootAM.invokeMethod(“updateEmployee”,params,classes);
}
}else{
// Invoke AM method “createRow”
rootAM.invokeMethod(“createRow”);
}
}
A few points:
- HashMap(key,value) is used to pass parameters, values from one page to another.
- To redirect from one page to another page using setForwardURL, forwardImmediately(), to same page is forwardImmediatelyToCurrentPage()
- Any parameter passed from any source we use pageContext.getParameter(String varName) to get the value of the parameter.
Now let’s launch the page to test.
Select a record and click update icon and it will take us to the create employee page, update the data and hit submit.
Verify the data in database table.
Hope this helps.