Tuesday, July 24, 2007

ADF:Invoking AM methods from the Managed Bean

Pure JSF way:
-------------

FacesContext facesContext=FacesContext.getCurrentInstance();
ExpressionFactory exp=facesContext.getApplication().getExpressionFactory();
MethodExpression getDeptNames = exp.createMethodExpression(facesContext.getELContext(),
"#{bindings.getAllDepts.execute}", null,new Class[]{});
HashMap map=(HashMap)getDeptNames.invoke(facesContext.getELContext(),null);



ADF way:
---------

Packages to be imported

import javax.el.ExpressionFactory;

import javax.faces.application.Application;
import javax.faces.context.FacesContext;

import oracle.adf.model.OperationBinding;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;

Sample Code Snippet:
-------------------
FacesContext fctx = FacesContext.getCurrentInstance();
Application app = fctx.getApplication();
ExpressionFactory exp=fctx.getApplication().getExpressionFactory();

DCBindingContainer bc;
bc = (DCBindingContainer)exp.createValueExpression(fctx.getELContext(),
"#{bindings}",DCBindingContainer.class).
getValue(fctx.getELContext());

//Get Current Row Handle
DCIteratorBinding iter = bc.findIteratorBinding("Emp2Iterator");
Row row = iter.getCurrentRow();
Number empNo = (Number)row.getAttribute("Empno");

//get Access to Method Binding

OperationBinding operation = (OperationBinding)bc.get("printANumber");
operation.getParamsMap().put("data", empNo);
operation.execute();

No comments: