Applying View Criteria from Application Module

Andrejus Baranovskis | Mar 13, 2010 10:56 +0000
Often we need to define and invoke View Object filtering. In ADF 11g we can do this by adding WHERE clause to View Object SQL statement or by defining View Criteria and invoking it later. I prefer second approach, why I should play with SQL statement, if ADF 11g can generate it for me. Okej, when there is View Criteria, it should be invoked. There are different approaches to do this - from declarative to programmatic. Today I will describe my preferred approach, I'm not saying you should use it as well.

Download sample application - AppModuleQuery.zip. This sample implements View Criteria to filter employees based on their department:


Here is the first trick - I have defined Bind Variable setter method to pass variable value and exposed this method through client interface:


This means I will call it later from Controller layer to pass correct Bind Variable value. Its important to say, you should do ExecuteQuery when new Bind Variable is passed, this will ensure it will be correctly reinitialized:


Now most interesting part starts, you can declare View Criteria to be executed automatically, each time when View Object is accessed. You can do this in Application Module - select View Object from Data Model section and click Edit:


Select View Criteria you want to trigger automatically - it will be invoked each time when View Object will be accessed:


Model part is done, now its time to look into Contoller. As you remember, Bind Variable setter method was exposed through client interface, it is present in Data Control:


Drag and drop it into ADF Bounded Task Flow, it is needed to set correct Bind Variable value. In my case it is defined as Default Activity:


On runtime, JobId value is passed as Input Parameter for ADF Bounded Task Flow, where it is used for Bind Variable setter method parameter:


ADF Bounded Task Flow is opened, Bind Variable value is set and View Criteria applied automatically:

A Reader Asks – How To Pass Table Export Id Into ADF 11g Declarative Component

Andrejus Baranovskis | Mar 10, 2010 12:36 +0000
"I'm trying to use ExportCollectionActionListener inside Declarative Component, but I can't pass table export Id correctly - it gives error, Id is not found. Is it possible to make it work?"

Yes, it is. Download sample application - DCLibExport.zip. This archive contains two JDeveloper 11g applications - Declarative Component (ExportToolbarLib) and consuming application (EmployeesExport). I will not talk about Declarative Components in this post, you can read more about them from previous post.

Declarative Component example is really simple, it contains one attribute - exportId. Such type of components are really useful for proper application design and architecture, it allows to achieve proper reusability - instead of declaring Export buttons for each table, we are doing it only once:


And one button with ExportCollectionActionListener assigned, this will allow to export table data to Excel format automatically:


Important thing to mention - ExportCollectionActionListener gets ExportedId property value from Declarative Component attribute:


This means, we will be able to provide table Id value directly from consuming page and reuse Declarative Component in many pages.

Consuming application declares Tag library for Declarative Component - ExportToolbar:


Library is available in Component Palette:


Consuming page structure defines three main elements: data table, panel collection and export toolbar (our Declarative Component):


Here is main question now - how to wire together Export listener from Declarative Component and table in consuming page. The main trick - we should declare complete path and pass it through ExportId attribute. We should specify ExportToolbar Id (et1), enter into this component, and reference Panel Collection (pc1) from there. Finally, we need to access table component (t1) itself. Expression language for this case: #{et1::pc1:t1}:


On runtime we can see Export button from Declarative Component and ADF table with data:


Export works successfully:

Integration in Oracle ADF with ADF Task Flows and Dynamic Regions Navigation

Today one more post from Integration series. There is a case, when Dynamic Region might have navigation to another Dynamic Region. If user will open one region from another, menu selection should be refreshed accordingly. I'm describing how to do this, thanks to blog Reader who asked this question.

Download updated sample - ADFIntegrationRegions3.zip, based on my previous post. Main change comparing to previous post sample - there is ADF Task Flow call from Locations to Departments:


All separate applications are deployed and assembled into one main application, same as it was described before. Only one difference now - first Dynamic Region (Locations) contains Departments buttons, it will navigate to second Dynamic Region (Departments) directly:


User can click on Departments button:


And here we go - Departments Dynamic Region is opened, menu item selection is synchronized as well:


Well, how to implement this? There is a very good hint in Frank Nimphius and Lynn Munsinger book (Building RIAs w/ Oracle ADF) on page #201 RegionNavigationListener. We can declare it for af:region:


And listen for navigation from Locations to Departments, if such navigation happens - we reset menu and switch Dynamic Region (Departments) as current:


Its how it works.

Red Samurai Tool – How To Check ADF 11g Package Structure and ADF Task Flow Parameters

In my previous post, I have introduced our JDeveloper 11g extension for ADF code quality validation. I will describe two rules more and will show how you can scan your ADF project for standard guidelines violations. Package structure check and task flow input parameters are documented today.

I'm demonstrating rule execution using updated sample application - RedSamuraiToolTestSample1.zip. Just to remind you, extension can be invoked by right clicking on Model or ViewController project and selecting it from available menu:


I will choose to run Package Structure Check rule:


Several violations are reported for - Application Module, View Link and Association:


Let's double check Model project structure, and we can see that report was correct - we need to fix few things for application package structure:


First, I will refactor Application Module into appmodules package:


If we run same rule again, this time only two violations will be reported - good progress:


We need to complete the rest of refactoring for View Link and Association - whole picture is correct now:


This is confirmed by our extension as well - no more violations for package structure:


Different projects may have different package structure standards, you can customize Red Samurai extension execution through preferences window:


Another rule I will describe - ADF Task Flow parameters naming convention:


Let's assume, we have a standard to give in prefix for ADF Task Flows parameter names. Developer forgot this standard and gave incorrect name - myParameter:


We run our rule to scan for ADF Task Flow input parameters names:


And here we go - rule violation is reported:


When parameter name is fixed to be inLastName:


No more violations for this rule are reported:

Red Samurai Tool – JDeveloper 11g Extension to Validate ADF Code Quality

I was working long on JDeveloper 11g extension for ADF 11g code quality checks. Finally it is available for public use - first release. This release is based on my Oracle Forms to Oracle Fusion 11g migration experience.

You can download extension - redsamuraiqt_1_0.zip and install it through JDeveloper Update wizard. It is available directly from Oracle JDeveloper Open Source and Partners Extension update center as well. Additionally, you can download sample project I'm using for this post - RedSamuraiToolTestSample.zip.

When you will run it, first screen will be welcome screen:


Next, you will be given with a list of rules to be applied for ADF code quality validation:


And finally, we have confirmation screen:


Extension can be customized through JDeveloper Preferences wizard:


You can install redsamuraiqt_1_0.zip extension through JDeveloper Check for Updates wizard from local file:


Or simply to download it from Open Source and Partner Extensions update center:


In order to invoke Red Samurai tool, right click on Model or ViewController project and select RedSamurai QT option:


To demonstrate extension functionality, I decided to show how you can ensure all View Objects contain ORDER BY clause:


It will report rule violations - View Object name and rule title:


Then you go to View Object screen and add ORDER BY clause:


If same rule is applied again, no more violations will be reported:


Another example - page title. We may have a rule to ensure all page titles are coming from Message Bundle file. If developer forgot to use title from Message Bundle and typed hard coded value:


Let's run Page Document Title rule:


Tool will generate report document, where violation will be reported:


It says that page title must be used from Message Bundle and property key should have specific value. I correct this violation and map page title to Message Bundle entry:


You can check,  Message Bundle reference should be included:


Run same rule again, no violations now:


Check for my next blog posts on the same topic - I will post updates and extension improvements.

Integration in Oracle ADF with ADF Task Flows and Dynamic Regions Pending Changes

From my previous post - Integration in Oracle ADF with ADF Task Flows and Dynamic Regions, you can learn how to integrate separate Oracle ADF applications using dynamic regions. I'm sure, you will want to prevent user navigation from one region to another, when there are unsaved pending changes available. Its pretty simple in ADF 11g, I will describe today.

I have updated sample application from my previous post, download updated archive - ADFIntegrationRegions2.zip.

So, how to prevent user navigation if there are unsaved changes? Key thing - from main application we can see Data Controls of imported applications. Even when main application Model project doesn't contain any ADF BC, still we can see Data Controls from imported ADF libraries:


And that is great, because we can access Data Control and check it for any existing uncommitted data.

I have implemented pending changes check inside Managed Bean, where Dynamic Regions are activated. In case of unsaved data, user is prevented from navigation and forced to stay in current region:


Pending changes are validated simply by accessing Data Control transaction and checking if it is dirty:


If there will be no pending changes, next dynamic region will be opened:


But, if user will type data and without saving will try to open another dynamic region, system will prevent him and inform about unsaved data:


Same rule works with form component:

How To Traverse ADF Tree

Andrejus Baranovskis | Feb 27, 2010 10:19 +0000
If you are thinking how to delete nodes from ADF tree, there is Frank Nimphius blog post - ADF Faces RC: Single row / Multi row delete from a tree component. However, Frank says that his blog entry is still a raw diamond and needs some polishing. In his example, if you remove root node, all child nodes still will remain in database. This means tree hierarchy will be broken. I decided to polish raw diamond, to describe how you can traverse ADF tree and remove all selected nodes together with children.

Download sample application - TreeTraversal.zip. This sample implements ADF tree traversal algorithm without recursion. ADF tree component provides Java API to get parent node for current node, this allows to avoid recursion.

I have defined tree binding and created action listener method, where tree traversal code is implemented:


Tree traversal algorithm scans selected nodes, and walks through all child nodes. When it reaches last child in tree branch, it returns back until it finds next child sibling. At the end it will return to the initial node, where tree traversal was started - root node.

I'm using two helper methods, one to get first child and second to get next sibling. Its ADF tree Java API, nothing special:


Let's see how it works. We can select multiple nodes, children of all those selected nodes will be traversed:


I intentionally commented node.getRow().remove; in my sample, just to prevent you from all nodes deletion by mistake :-) Traversed nodes are reported in the log:


It starts from first selection and walks from 100 to 102, reports parent node 90 and goes to second selection, walks through and reports parent node 110.

You can select such node, which contains multiple branches:


Tree traversal will work as well - it will enter first branch, traverse it and move to next sibling branch. Whole report for previous selection:


If you are planning to traverse large tree branches, you should increase ADF tree RangeSize property value. Default value is 25, means it will keep only 25 nodes in memory, so you will not be able to traverse whole hierarchy. With default RangeSize it will render large tree hierarchy structures pretty slow, I recommend to increase it to something at least 500:


It will keep 500 nodes in memory, and will allow such tree operations as Expand All Nodes and Expand All Nodes Below to perform faster.