Tuesday Feb 28, 2012

Best practice invoking business services methods from JSF beans

Recently there was an increasing interest on OTN in best practices for invoking methods exposed on the ADF Business Components client interface. There exist two options to access methods exposed on ADF Business Components application modules and view objects from a managed bean through ADF.

  • Call findDataControl(String) on the BindingContext and access the application module to invoke a method exposed on the Application Module or View Object client interface.

  • Create a method binding on a PageDef level that binds to a method exposed on the Application Module or View Object client interface

Speaking of best practices, it’s the second option  to use a method binding on the PageDef file that I recommend for the following reasons

  • ADF is about abstracting the view and controller layer from the business service implementation details. A method binding instead exposes an ID (the name o the binding) to the JSF developer, which they use to access the binding from a managed bean using the OperationBinding API. Signature or name changes of a method exposed on the business service thus don't require a change in the managed bean(s) referencing it. All changes would be applied in metadata.

  • ADF provides the OperationBinding class as an abstraction for business services methods. Configuring business service method access on the PageDef file using method bindings exposes a single and consistent API to application developers.

  • Programmatic access to a method exposed on the business service require more lines of code than accessing the same method through the binding layer

  • Direct business service access violates the recommendation to always work through the ADF binding layer and not to bypass it.

To access a method binding from a managed bean, use the following code

  BindingContext bctx = BindingContext.getCurrent();
  BindingContainer bindings = bctx.getCurrentBindingsEntry();
  OperationBinding operationBinding = 
       bindings.getOperationBinding("name_of_method_binding");
  //optional
  operationBinding.getParamsMap().put("argumentName1",value1);
  operationBinding.getParamsMap().put("argumentName2",value2);
  //invoke method
  operationBinding.execute();
  if (!operationBinding.getErrors().isEmpty()) {
     //check errors
     List errors = operationBinding.getErrors();
     ...
  }
  //optional
  Object methodReturnValue = operationBinding.getResult();


Sunday Jan 15, 2012

How-to invoke ADF bindings in page templates

ADF Faces page templates may have their own PageDef file defined to access the ADF binding layer or have ADF bound components added to the template.

ADF Faces pages that use the template will reference the template's PageDef file in the Executable section of their own PageDef file. In this sample, the template binding reference in the the template consumer page PageDef file is ptb1.

The code below invokes a method binding in the template's PageDef file from a command button on the page. The "trick" for accessing the template's PageDef file is to know that it is another instance of BindingContainer.

public String cb1_action() {
  BindingContext bctx = BindingContext.getCurrent();
  DCBindingContainer bindings = 
                (DCBindingContainer)bctx.getCurrentBindingsEntry();
  //access the page template Pagedef file reference in the 
  //Executable section of the consumer page's Pagedef file
  DCBindingContainer templateBinding = 
                    (DCBindingContainer)bindings.get("ptb1");
  //get the MethodBinding 
  OperationBinding printMethod = 
        (OperationBinding)templateBinding .get("printThis");
  //invoke the print method exposed on the template's PageDef file
  printMethod.getParamsMap().put("message","Hello World");
  printMethod.execute();
  return null;
}
 
  

About

The Oracle JDeveloper forum ranks in the Top 5 of the most active forums on the Oracle Technology Network (OTN).



The OTN Harvest blog is a summary of selected topics posted on the OTN Oracle JDeveloper forum.



It is an effort to turn knowledge exchange into an interesting read for developers who enjoy little nuggets of wisdom





Frank Nimphius

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today