How to Update Data in OAF

Here we will learn about updating the data in OAF. Along with this we will also see the following:

  1. Redirect from one Page to another.
  2. Pass Parameters from one Page to another.
  3. SPEL
  4. Dynamically execute VO Query.

Let’s start.

  1. Right Click on ResultRN to add new column UpdateCol.1
  2. Right Click on columnHeader to add header.
    ID: UpdateColHdr
    Prompt: Update
  3. Right Click on UpdateCol to add an image item.
    ID: Update
    Item Style: image
    Prompt: Update
    Image URI: updateicon_enabled.gif
  4. 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.

  5. 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: XXRDSearchEmpCO2
  6. 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.

3

Verify the data in database table.

4

Hope this helps.

Leave a Reply

Your email address will not be published. Required fields are marked *

Show my latest post here