Wednesday, 28 October 2015

OAF: Calling AM method from CO in Oracle Application Framework

In this post I just want to put some sample code to show how to call the Application Module (AM) methods from the Controller (CO). The reason for this post with the basics is because, I still see in the OTN forum that AM methods are not called in the recommended approach.

In this post I have given example for methods with parameters, without parameters, couple of different types of parameters and methods with return types.

Sample 1:- AM method without parameter and return type.

AM Method:
 public void methodWithoutParams()  
 {  
   System.out.println("Dummy Method");  
 }  
CO Code:
 import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;  
 OAApplicationModuleImpl appModule = (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);  
 appModule.invokeMethod("methodWithoutParams");  

Sample 2 :- AM method with parameters and return type.

AM Method:
 public String methodWithParams(String[] strArray,String strVal)  
 {  
      System.out.println("strVal: " + strVal);  
      for(int i = 0; i < strArray.length; i ++)       
      {  
           System.out.println("strArray["+i+"]: " + strArray[i]);  
      }  
      return "Success";  
 }  
CO Code:
 import oracle.apps.fnd.framework.server.OAApplicationModuleImpl;  
 import java.io.Serializable;  
 OAApplicationModuleImpl appModule = (OAApplicationModuleImpl)pageContext.getApplicationModule(webBean);  
 String[] strArray = {"1","2"};  
 String strVal   = "AJ";  
 Serializable[] params = {strArray, strVal};  
 Class[] paramTypes  = {String[].class, String.class};  
 String returnVal = (String)appModule.invokeMethod("methodWithParams", params, paramTypes);  
 System.out.println("returnVal : "+ returnVal);  

If we need to deal with non-Serializable parameters, refer : http://www.adftraining.com/blog/how-to-call-am-methods-from-controller-without-using-invokemethod

Feel free to point out if anything is missing/wrong in this blog.

No comments:

Post a Comment