How to call API from OAF page using button action - OA Framework



In this tutorial we will see how to see call API from OAF page using button action .Usually if complex validations need to perform then it is a better approach to pass all the complex work to database and get the results back to OAF Page. This will improve the screen performance.

In this example we will reuse OAF page built in the last tutorial using transient attributes and integrate with Supplier API to create a Supplier and Supplier Site in AP Module.

Pre-requisites: 

If you are new to OAF we highly recommend to refer the below tutorial to setup jDeveloper

Step 1 : Right click on the Project created in the last tutorial and set a New Controller for it.


How to call API from OAF page using button action - OA Framework


Step 2 : - Add the following code in the AMImpl Class in this Scenario it is SupplierMainAMImpl.java file.

//Below code will initialize a new Row in the Transient VO so that user entered values can be captured.
public void initRow(){ OAViewObject vo = getSupplierDummyVO(); if (!vo.isPreparedForExecution()) { vo.executeQuery(); } Row row = vo.createRow(); vo.insertRow(row); row.setNewRowState(Row.STATUS_INITIALIZED); }

Step 3:- Call this method from the New Class Setup in the step-1 under proceessRequest.

public void processRequest(OAPageContext pageContext, OAWebBean webBean)
{
 super.processRequest(pageContext, webBean);
 OAApplicationModule am = pageContext.getApplicationModule(webBean);
 am.invokeMethod("initRow", null);
}

Step 4:- Invoke the API which is defined in the earlier tutorial from the AM and pass the values which user has enters in the UI. 

Copy the below code to the AMImpl.java File. Below method will return the Status of the API with a Message back to the CO.
     public String[] importSupplier(){
        OADBTransaction oadbtransaction = (OADBTransaction)getTransaction();

         String[] res=new String[2];

         String str="begin xxdcb_supplier_imp.create_supplier (\n" + 
         "                              p_supplier_number            =>?,\n" + 
         "                              p_supplier_name              =>?,\n" + 
         "                              p_supplier_site_code         =>?,\n" + 
         "                              p_ou                         =>?,\n" + 
         "                              p_addr1                      =>?,\n" + 
         "                              p_country                    =>?,\n" + 
         "                              p_purchasing_site_flag       =>?,\n" + 
         "                              p_pay_site_flag              =>?,\n" + 
         "                              p_status                     =>?,\n" + 
         "                              p_ret_msg                    =>?); " +
         " end;";
      

         OracleCallableStatement oraclecallablestatement = 
          (OracleCallableStatement)oadbtransaction.createCallableStatement(str, 1);

         try{
         
          OAViewObject vo =getSupplierDummyVO();
          Row r=vo.getCurrentRow();
          String supplierNumber    =(String)r.getAttribute("supplierNumber");
          String supplierName      =(String)r.getAttribute("supplierName");
          String supplierSiteCode  =(String)r.getAttribute("supplierSiteCode");
          int OUId                 =Integer.parseInt(r.getAttribute("OUId").toString());
          String siteAddressLine1  =(String)r.getAttribute("siteAddressLine1");
          String siteCountry       =(String)r.getAttribute("siteCountry");
          String PurchasingSiteFlag=(String)r.getAttribute("PurchasingSiteFlagEnabled");
          String PaySiteFlag       =(String)r.getAttribute("PaySiteFlagEnabled");
        
          oraclecallablestatement.setString(1,  supplierNumber );
          oraclecallablestatement.setString(2,  supplierName );
          oraclecallablestatement.setString(3,  supplierSiteCode);
          oraclecallablestatement.setInt   (4,  OUId );
          oraclecallablestatement.setString(5,  siteAddressLine1 );
          oraclecallablestatement.setString(6,  siteCountry );
          oraclecallablestatement.setString(7,  PurchasingSiteFlag );
          oraclecallablestatement.setString(8,  PaySiteFlag );

          oraclecallablestatement.registerOutParameter(9, Types.VARCHAR);
          oraclecallablestatement.registerOutParameter(10, Types.VARCHAR);

          oraclecallablestatement.execute(); 
                           
          res[0]= oraclecallablestatement.getString(9);
          res[1]= oraclecallablestatement.getString(10);
          return res;
         }
         catch(Exception e)
         {
          throw OAException.wrapperException(e);
         }
     }

Step 6:- Save all your changes and test the page.

How to call API from OAF page using button action - OA Framework

How to call API from OAF page using button action - OA Framework

From DB:

 From Front End



If you try to create a same supplier one more time.


No comments