January 26, 2018

Resolving or Invoking a Method Expression from a Managed Bean in Oracle MAF

[MAF 2.3.1]

I developed a mobile app using Oracle Mobile Application Framework (MAF) in which I had a requirement to invoke a method from a managed bean method. Below is the code snippet worked for me to do this.


public static Object resloveMethodExpression(String expression,
                                             Class returnType,
                                             Class[] argTypes,
                                             Object[] argValues) {
  MethodExpression methodExpression = AdfmfJavaUtilities.getMethodExpression(expression,
                                                                             returnType,
                                                                             argTypes);
  return methodExpression.invoke(AdfmfJavaUtilities.getAdfELContext(), argValues);
}


Where,
  •  expression:  the managed bean method EL expression
  • returnType:  Class name of the return value of the method, can be null if it is void
  • argTypes: Class names of the input parameters need to be passed to the method if any. It would be null if there are no parameters
  • argValues: Input parameter values to be passed to the method if any. It would be null if there are no parameters