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:
Sample 2 :- AM method with parameters and return type.
AM Method:
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.
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:
CO Code:
public
void
methodWithoutParams() { System.out.println(
"Dummy Method"
); }
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:
CO Code:
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"
; }
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.