Wednesday, October 30, 2013

OAF Controller Extension

How to extend a standard controller CO?

I have a standard page in HRMS module and  have a business requirement to have additional check(Validations) to be performed before i click Transfer button. Transfer button Will have a standard controller.

How to find the controller Name?
Click About this page hyperlink displayed at bottom of the page where your controller has to be extended.

Note: FND: Diagnostics (FND_DIAGNOSTICS) profile option to Yes to render the "About this page" link at the bottom of each OA Framework-based page.

1)Unbook the Business components hierarchy
2)It will display all the BC4J components of the OA page.
3)Find the controller at $JAVA_TOP/oracle/apps/per/wpm/objectives/webui
4)Download the controllerCO.class file from "oracle/apps/per/wpm/objectives/webui" to your local system. Your controller will be applicable based on the application top.
5)Decompile the class file to get java file using CAVAJ utility.
6)Open the Original Java file and Start modify the processFormRequest( ) Method. I have highlighted the changes done to achieve the business requirement.

 package xx.oracle.apps.per.wpm.objectives.webui;

import com.sun.java.util.collections.HashMap;
import java.io.Serializable;
import oracle.apps.fnd.common.VersionInfo;
import oracle.apps.fnd.framework.OAApplicationModule;
import oracle.apps.fnd.framework.OAException;
import oracle.apps.fnd.framework.webui.OAPageContext;
import oracle.apps.fnd.framework.webui.beans.OAWebBean;
import oracle.apps.fnd.framework.webui.beans.form.OASubmitButtonBean;
import oracle.apps.per.selfservice.common.SSHRParams;
import oracle.jbo.domain.Number;
import oracle.apps.per.wpm.objectives.webui.*;
import oracle.apps.fnd.framework.OAFwkConstants;
import oracle.apps.fnd.framework.server.OADBTransaction; //to establish DB connection
import java.sql.CallableStatement; //to execute a package.procedure
import java.sql.Types;//used for type conversions and VARCHAR2



// Referenced classes of package oracle.apps.per.wpm.objectives.webui:
//            ObjectivesPageCO

public class XXSetObjectivesPageCO extends SetObjectivesPageCO
{

    public static final String RCS_ID = "$Header:" +
" ship $"
;
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header:" +
" ship $"
, "oracle.apps.per.wpm.objectives.webui");

    public XXSetObjectivesPageCO()
    {

           //Constructor;
    }


    public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    {
   
      super.processRequest(oapagecontext, oawebbean);
    //I need standard processRequest method to be executed first.
    }

   
    public void processFormRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    {
      String p_return_msg  = null;
      if(oapagecontext.getParameter("MgrTransfer") != null) //This is the Transfer Button ID name
       {
        OADBTransaction tx = oapagecontext.getRootApplicationModule().getOADBTransaction();
    
                  String sql="BEGIN " +
                 "XXValidateProc("+
                                   "p_param_1=> :1,"+    
                                   "p_return_msg => :2);"+
                                   "       END;";           
          CallableStatement cStmt = (CallableStatement)tx.createCallableStatement(sql, 1);
          if(cStmt!=null) 
               {
                         try { 
                       
                         cStmt.setString(1,oapagecontext.getDecryptedParameter("
p_param_1"));      
                         cStmt.registerOutParameter(2,Types.VARCHAR);                            
                         cStmt.execute();                                                           
                         p_return_msg = cStmt.getString(2);                                                  
                         cStmt.close();                                                             
                         }
                        catch(Exception e)
                        {
                          throw new OAException("SBM: Error Calling XXValidateProc" + e.toString(),OAException.ERROR);
                        }
                                         
                }
        if(!p_return_msg.equalsIgnoreCase("No Errors")){
                  throw new OAException(p_return_msg,OAException.ERROR);                                           
        }
        else
        {
                         super.processFormRequest(oapagecontext, oawebbean);
        }       
       
     
    }
    else

   { //In case of any exception in the custom procedure, I want the standard controller method's to be called.
     super.processFormRequest(oapagecontext, oawebbean);
   }
     
    }
    }
   
Migration of OA Controller Extension

1)Create a folder under $JAVA_TOP xx/oracle/apps/per/wpm/objectives/webui;
2)Move the  XXSetObjectivesPageCO.java to the above location.
3)Compile the Java using javac XXSetObjectivesPageCO.java
4)Once compilation is done successfully.
5) Goto the page where the Controller is extended. Click Personalize Page Option.

Note: Personalize Self-service Defn (FND_CUSTOM_OA_DEFINTION) profile option should be enabled.


 Go to The regions where controller is got extended. Inherit the Controller location as

xx/oracle/apps/per/wpm/objectives/webui/XXSetObjectivesPageCO

Controller Extension is Done :)