Showing posts with label JDeveloper. Show all posts
Showing posts with label JDeveloper. Show all posts

Friday, 21 February 2014

Create ADF operation binding code in JDeveloper in a quick way

Let's assume we have an operation exposed in our data control, that we need to invoke programmatically from our managed bean that is behind the fragment we are working on; the following is a quick trick to make JDeveloper generate the operation binding access code for us (in this case, we want to execute the 'retrieveUserInfo' operation):



The first step is to drag and drop the operation into our page or fragment, selecting Method > ADF Button:



Once we do this, JDeveloper will generate the corresponding binding for us in the page Definition file for the page/fragment, and then finally it creates a commandButton component on the page, having its action listener pointing to the newly created binding.



Once the commandButton has been created, right click on the component, and select 'Create Method binding for action', then selects the managed bean we want to create the code into:






If we have a look to the bean, we will notice that JDeveloper has generated the necessary code for us to be invoked.

BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
OperationBinding operationBinding = bindings.getOperationBinding("retrieveUserInfo");
operationBinding.getParamsMap().put("username", userName);
operationBinding.execute();


At this point we can remove the commandButton component from the page, deleting it manually from the code; please DO NOT DELETE IT USING THE STRUCTURE PANEL as it will delete the binding as well!

Wednesday, 19 February 2014

How to enable ADF Diagnostic Logging in JDeveloper

I usually refer to this presentation of Steve Muench:

in this presentation many topics related to ADF debugging/logging are covered, like:

  • Enable Diagnostic Logging (covered in this article)
  • Debug with the Business Components Tester
  • Create a Command-Line Test Client Program
  • Export Debugger Call Stack and Exact JDev/ADF Version
  • Set Up and Use Oracle ADF Source for Debugging
  • Conditional breakpoint expressions
  • Breakpoints on Task Flow Activities
  • ADF Structure and ADF Data Windows
  • Breakpoint on Action Bindings in Page Definition
  • EL Evaluator Window
  • Logging Executed Queries and Fetched Rows

Also this article from Shay Shmeltzer gives a very good overview of the ADF Debugger features (setting breakpoints on various ADF artifacts, using the ADF structure window, ADF Data window and EL Evaluater window).

This article only focuses on enabling the diagnostic logging.

At first, it is useful to make sure the log is saved to the file system, for further analysis:



First setup the log viewer:




Then from the project properties, create a new Run/Debug profile:



Give the profile a name:



Add the string '–Djbo.debugoutput=console' to the Java Options:



Finally, make sure you are using the new Run/Debug configuration:


Saturday, 5 November 2011

Accessing an ADF Operation binding programmatically

Developing an ADF application, it sometimes comes out we need to invoke programmatically (e.g. from a Managed Bean) a method exposed as operation binding in a ADF Data Control. To do this, we need to access the current binding container:

OperationBinding searchOp = ADFUtils.findOperation("searchBusinessUnits");
The ADFUtils.findOperation() method has the following definition:
public static OperationBinding findOperation(String operationName) {
OperationBinding op = getDCBindingContainer().getOperationBinding(operationName);
if (op == null) {
throw new RuntimeException("Operation '" + operationName +"' not found");
}
return op;
}

Unfortunately, when the previous code is executed in a method action invoked at page load time through an invokeAction binding, it happens that the reference to the binding container is null at this point. In this case, we need to access the binding container in a different way, using EL:

import oracle.adfinternal.view.faces.model.binding.FacesCtrlActionBinding;

[. . .]

FacesCtrlActionBinding searchOp = null;
searchOp = (FacesCtrlActionBinding)JSFUtils.resolveExpression("#{data.portal_peoplefinder_resultsPageDef.searchBusinessUnits}");
Map opParams = searchOp.getParamsMap();
opParams.put("searchTerm", searchString);
Object result = searchOp.execute();

The pageDef excerpt of the page (or page fragment) containing the binding I need to access (in this case peopleFinder_resultsPageDef.xml ):

<bindings>
[...]
<methodAction id="searchBusinessUnits" InstanceName="ContentServicesDC.dataProvider"
DataControl="ContentServicesDC" RequiresUpdateModel="true"
Action="invokeMethod" MethodName="searchBusinessUnits" IsViewObjectMethod="false"
ReturnName="data.ContentServicesDC.methodResults.searchBusinessUnits_ContentServicesDC_dataProvider_searchBusinessUnits_result"/>
[...]
</bindings>

And the line of DataBindings.cpx regarding this binding:

<page id="portal_peoplefinder_resultsPageDef"
path="oracle.webcenter.portalapp.pagefragments.peoplefinder_resultsPageDef"/>

IMPORTANT: the EL expression we are using to retrieve the binding must be comply with the following format:

[“data”] + [id of the corresponding <page> entry in DataBindings.cpx] + [name of the binding we want to retrieve]

Executing custom code at page load time via ADF Data Control

This is a very common use case: invocation of some custom code at page load time.

Thanks to ADF Data Control capability, we can incapsulate our custom code in a method of a POJO, and finally expose this as a Data Control (it's worth reminding that it complies with JSR 227 specification, so it's actually adherent to Java standards).

As we have many flavours of bindings, we are going to show in this tutorial how to achieve the same result using an attribute binding, and then using a method binding.

For this tutorial JDeveloper 11.1.1.5.0 has been used.

As a first step, let's create a new Fusion Web Application (ADF) :



In the Model project we now create a new Java class, named PageLoadDC:




and expose this class as a Data Control:


After this, the Data Controls panel is populated with the new item:

And the DataControls.dcx file is updated with the following content:



Now let's work on the ViewController project: at first we create a new JSF page, named home.jspx:




To make JDeveloper create the necessary bindings for you in the pageDef file for the new page, just drag & drop the method binding from the DataControls panel onto the page, choosing ADF Output Text as display mode for this binding:




In this way, many things happen behind the scenes:

–        a new pageDef for home.jspx page is created

–        a new binding for the method exposed in the data control is created

–        an iterator has been defined for this binding, to access the results of this method call.



The generated code in the newly created pageDef is:



Running the application gives the expected result:



An interesting observation:

Having named the DC method with a name starting with 'get' (in this case 'getContentAtPageLoad'), this is interpreted by ADF as a getter of a property 'contentAtPageLoad', so the binding definition is really an attribute binding rather than a pure method binding, and in the home.jspx page the following EL expression is used to retrieve the value:
#{bindings.contentAtPageLoad.inputValue}

Now we add a new method in the DC, this time naming it in a different name, e.g. 'buildContentAtPageLoad':



and we expose the file as a DC again:



we can now notice how a method binding is actually created.

Now in the bindings box select the Plus icon to create a new binding, the select methodAction:



In the next screen just select the DC we just created, and the method name will appear in the 'Operation' dropdown list, then press OK:



As a result, a new binding is created in the pageDef file, and it appears in the 'Bindings' box in the page overview :



Now, to make this methodAction execute when the page is loaded, we just need to create an invokeAction to actually invoke it: in the 'Executables' panel in the 'Bindings' tab for the home.jspx page just click the Plus icon and select InvokeAction:



In the 'InsertInvokeAction' select the 'buildContentAtPageLoad' method and assign it an arbitrary ID, then click OK:



Then select the newly created invokeActionBinding, and in the property inspector set the 'Refresh' dropdown to 'Always':



In the JSPX page set the EL expression for the new binding like that:



Running the page again we get the expected result:



Easy as a pie.

You can download the example JDeveloper project here (remove the .pdf extension before unpacking).