Showing posts with label Calling an Application Module method ADF. Show all posts
Showing posts with label Calling an Application Module method ADF. Show all posts

Monday, September 2, 2013

Managed Bean ( Concept ) / Calling a method in the AMImpl class from the Managed bean

Managed Bean : - It is a java class that is created in the view controller of the ADF application.
-> We can have one Managed bean for a task flow so that all the pages in the task flow can access that Managed bean.
-> In the over view of the task flow go to the managed bean and add the java class as a bean after we have created a java class in the view controller section of the application.
Note :- If we want to call a method in the backing bean from a page by setting it to a button action we have to add that method to the bindings of the page.

Call a method in the Application Module from the backing bean:-

import oracle.adf.model.binding.DCBindingContainer;
import oracle.adf.model.binding.DCIteratorBinding;
import oracle.binding.BindingContainer;
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import oracle.binding.OperationBinding;

  FacesContext facesContext = FacesContext.getCurrentInstance();
  Application app = facesContext.getApplication();
  ExpressionFactory elFactory = app.getExpressionFactory();
  ELContext elContext = facesContext.getELContext();
  ValueExpression valueExp =
    elFactory.createValueExpression(elContext, "#{bindings}", Object.class);
  BindingContainer binding= (BindingContainer)valueExp.getValue(elContext);
  // createCurrentCustomerRow is the name of the method in the AMImpl class
  OperationBinding operationBinding=binding.getOperationBinding("createCurrentCustomerRow");
  // Set the Input parameters to the operation bindings as below
     operationBinding.getParamsMap().put("pCustomerID", "100");  
  // Invoke the Application module method
  operationBinding.execute();
  // Get the result from operation bindings
  Object obj =operationBinding.getResult();