Thursday, March 11, 2010

ADF 11g Declarative Components example

Here is a simple example of creating a declarative component to ensure a consistent look and feel for "Address" (Street, City, PostalCode, Country).

Nice definition from an OOW 2009 preso from Lynn M.
Declarative components are -
-Component definitions that are reusable across applications
-When changed, affect all pages that use them
-Made up of any number of other components
-Do not have data binding in their definition
-Published for use in the Component Palette

Now to the lab.

First the SQL to create the demo table -

Drop table myCusts;

Create Table myCusts
cust_nr varchar2(20) not null,
cust_name varchar2(40) not null,
cust_email varchar2(40) not null,
cust_telnr varchar2(40) not null,
cust_addressStreet varchar2(40) not null,
cust_addressCity varchar2(40) not null,
cust_addressZip varchar2(10) not null,
cust_addressCountry varchar2(40) not null,
cust_age number(3),
cust_salary number(8),
comments varchar2(255))
alter table myCusts add
primary key (cust_nr)

Friday, March 5, 2010

Managing ADF Customizations with MDS

In this simple scenario I am an ISV who needs to deliver different versions of my app to different customers. I also want to give end users the possibility to „personalize“ the application.

A customized application contains a base application and one or more layers
containing customizations. MDS stores the customizations in a metadata repository and retrieves them at runtime to merge the customizations with the base metadata to reveal the customized application. Since the customizations are saved separately from the base, the customizations are upgrade safe; a new patch to base can be applied without breaking customizations. When a customized application is launched, the customization content is applied over the base application.

Seeded customization of an application is the process of taking a generalized
application and making modifications to suit the needs of a particular group, such as a specific industry or site. Seeded customizations exist as part of the deployed application, and endure for the life of a given deployment.

package oracle.model.cust;


import java.util.Properties;

import oracle.mds.core.MetadataObject;
import oracle.mds.core.RestrictedSession;
import oracle.mds.cust.CacheHint;
import oracle.mds.cust.CustomizationClass;

public class CustCC extends CustomizationClass {
private static final String DEFAULT_LAYER_NAME = "CustSite";
private String mLayerName = DEFAULT_LAYER_NAME;

public CustCC() {

public CustCC(String layerName) {
mLayerName = layerName;

public CacheHint getCacheHint() {
return CacheHint.ALL_USERS;

public String getName() {
return mLayerName;

public String[] getValue(RestrictedSession sess, MetadataObject mo) {

// This needs to return the site value at runtime.
// For now, it's always null.
Properties properties = new Properties();
String configuredValue = null;
Class clazz = CustCC.class;
InputStream is = clazz.getResourceAsStream("/");
if (is != null){
try {
String propValue = properties.getProperty(mLayerName);
if (propValue != null){
configuredValue = propValue;
} catch (IOException e) {
return new String[] {configuredValue};


Step 4 - Add the customization class available to the MDS Configuration, by editing the adf-config.xml file.

Step 5 – Create the file in the Model project. Ensure it is in the \src directory.

Add the following entries

#Configured values for the default layer values

Step 6 – These “layer” values must also be added to the base CustomizationLayerValues.xml file.

Add the following entries –

Step 7 – In JDeveloper, Switch to customiser role
Tools / Preferences / Roles

View Customization Context

Customising the ADF Model
In this section we will customise the Model for Cust2 and add the emp_email attribute to EO and VO.

Step 1 – Enter Edit mode and select Cust2

Step 2 - In SQLPLUS, add the new column to the table.
alter table myEmps add
(emp_email varchar2(20))

Step 3 – Amend the Model project and add the emp_email attribute to the EO and VO.

This change is saved in a separate xml file, specific for cust2.

Do the same for the VO.

Customizing the UI
In this section we will amend the browseEmps.jspx to include the emp_email attribute for cust2.

Step 1 – open browseEmps.jspx.

The datacontrol now includes the new attribute –