Posts

Showing posts from October, 2018

Manual passivation and activation of Application Module instance variables

Image
JDev version: 12.2.1.3.0
We are aware of ADF's passivation and activation mechanism. We know that when we need to persist the state of a transient attribute of a view object, we ask the framework explicitly to passivate such an attribute.
However, sometimes we may also need to persist the state of an Application Module class' member variable. Let us say that we have an Integer variable which gets incremented on a certain operation. At a high user load, or when doFailover is turned on, the application module instance is passivated and activated almost on every request.
The ADF framework passivates only that data which is required to initialize the application module to the earlier state, and the ones that we explicitly ask for (by checking the passivate checkbox). All other instance level values are rejected and re-initialized. Let's see an example.
To demonstrate this, I have turned off application module pooling, to ensure all requests are forced to be passivated to the d…

Advanced programmatic view object in 12.2.1.x

Image
JDev version: 12.2.1.3.0 Source: GitHub
The previous versions of ADF required a lot of knowledge of framework methods, while attempting to create programmatic view objects based on non-SQL data sources, such as a PL/SQL ref cursor.
This blog shows you how to create a search form, which passes a department id to a packaged procedure, and display results based on a ref cursor returned by the procedure.
Create a simple procedure, which returns some employee data, based on a department_id entered by user.

Create a view object - EmployeesVO, and select Programmatic while selecting Data Source. Create the necessary view object implementation class. Create transient attributes for the columns you need to display on the GUI.


If you open the EmployeesVOImpl class, you will see that JDev has extended it from oracle.jbo.server.ProgrammaticViewObjectImpl.

This class contains an overridden getScrollableData method, and this is the only method we need to populate in order to display data from the …

Keyboard shortcuts on ADF table

Image
JDev version: 12.2.1.3.0 Source: GitHub
We often create applications which require very quick data entry. As a real world example, imagine creating a supply-chain application for an e-commerce vendor. The computers available at warehouses are not equipped with mouse either. A common request from such users is to enable the application with the usual keyboard shortcuts, in order to allow fast data entry.
Now, there is a great deal of discussion as to how much we should be overriding the default browser shortcuts. Some web developers are quite vocal in their view of not overriding basic browser shortcuts such as Ctrl+S, Ctrl+T or Ctrl+W. That discussion is beyond the scope of this blog.
This blog mainly deals with creating custom shortcuts, along with Control or Shift key modifiers.
The setup is simple - an ADF application which displays employee records from the HR schema. The user selects a record and uses keyboard short-cuts to perform operations such as:
a) copying and pasting a r…

Efficient dynamic query in ADF

Image
JDev version: 12.1.3.0.0 Source Code: GitHub
Use Case: Quite often, we are required to attach dynamic where clause to an ADF view objects's query. Although we do have view criteria to support our cause, more often than not, they do not quite support complex business logic to derive dynamic where clauses.
The GUI:


We usually make use of ViewObject's setWhereClause API to attach a dynamic where clause. However, a common mistake is to write a dynamic query like this:

Now this approach, although technically correct, leads to 2 problems: 1. SQL Injection - imagine someone passing first-name as 'Steven' (with quotes). Your entire SQL statement goes for a toss. 2. Improper query caching - let's explain this with some data and examples.
Imagine you have a very complex query, running on a table with a huge volume of records. The DBAs will usually attach a SQL profile to your query. Now when you have a sql which is a new String for every execution, it effectively creates a ne…