Difference between revisions of "Custom Application ADF Library Overrides"

From ADF Docs
Jump to: navigation, search
(Overview)
(Steps to override)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
== Overview ==
 
== Overview ==
The ADF application can override a component in the ADF library.  The ''components'' directory can contain a sub directory named ''lib''Any library components can be placed in this directory to override the matching ADF library component.
+
You should have learned that you can "inject" ADF Library Components ([[App Bean Config]]) into your application.  However, you can also override ADF Library Components and deliver that override with your application.
  
The [[App Bean Config|App Bean Config]] looks in this directory to find if any ADF library components are to be replaced with the ADF application level component.
+
== Why would you override an ADF Library Component ==
 +
There are many reasons to override an ADF Library Component in your application.  One of those reasons is to make a minor modification to the ADF Library Component without affecting other applications/code that use the original component.
  
 +
== Steps to override ==
 +
# Create a directory called "lib" in your applications directory (e.g. /myApp/lib)
 +
# Copy your ADF Library Component from its directory and place it int your /myApp/lib/ directory
 +
# Modify the <cfcomponent> tag to extend the original ADF Library Component.  For example, if you wanted to modify data_1_0.cfc in your application the <cfomponent> tag would be changed from this:
 +
<source lang="cfm">
 +
<cfcomponent extends="ADF.core.Base">
 +
</source>
 +
to:
 +
<source lang="cfm">
 +
<cfcomponent extends="ADF.lib.csData.csData_1_0">
 +
</source>
  
'''Developers Tip:''' Have the override component in your application extend the ADF library component.  This enables you to use all the same functions in the library component, but override or add some functions.
+
# Update the application appBeanConfig.cfm to create a singleton for this component.  The second parameter must be a unique bean name for the component.  Add a dependency for this new bean into the application.
 +
<source lang="java">
 +
// Load the customized CSData for the application
 +
addSingleton("ADF.apps.myApp.lib.csData_1_0", "myApp_csData");
 +
addConstructorDependency(appBeanName, "myApp_csData", "csdata");
 +
</source>
 +
 
 +
== Best practices ==
 +
You don't have to override the entire component, you can add new methods and override existing methods pretty easily.  Using the above example, lets say you wanted to modify <em>just</em> the "getStandardMetadata()" function so it would return more data than it does now.  A sample of your csData_1_0 (located in the /myApp/components/lib/ directory) would look like this:
 +
 
 +
<source lang="java">
 +
<cfcomponent displayname="CSData" extends="ADF.lib.csData.csData_1_0">
 +
 +
<cfproperty name="version" value="1_0_0">
 +
<cfproperty name="type" value="singleton">
 +
<cfproperty name="data" type="dependency" injectedBean="data_1_0">
 +
 
 +
<cffunction name="getStandardMetadata" access="public" returnType="query">
 +
{your changes here}
 +
</cffunction>
 +
 
 +
</cfcomponent>
 +
</source>
 +
 
 +
Notice how the value of the "extends" attribute is pointing to the csData_1_0 component loaded into the ADF <em>and</em> notice how there are no other methods in this component.  By extending the original csData_1_0 component, you automatically gain all of the methods defined in that component - so you need not copy those in.
 +
 
 +
This allows you to take advantage of any changes made to csData_1_0 automatically.

Latest revision as of 18:15, 8 April 2010

Overview

You should have learned that you can "inject" ADF Library Components (App Bean Config) into your application. However, you can also override ADF Library Components and deliver that override with your application.

Why would you override an ADF Library Component

There are many reasons to override an ADF Library Component in your application. One of those reasons is to make a minor modification to the ADF Library Component without affecting other applications/code that use the original component.

Steps to override

  1. Create a directory called "lib" in your applications directory (e.g. /myApp/lib)
  2. Copy your ADF Library Component from its directory and place it int your /myApp/lib/ directory
  3. Modify the <cfcomponent> tag to extend the original ADF Library Component. For example, if you wanted to modify data_1_0.cfc in your application the <cfomponent> tag would be changed from this:
<cfcomponent extends="ADF.core.Base">

to:

<cfcomponent extends="ADF.lib.csData.csData_1_0">
  1. Update the application appBeanConfig.cfm to create a singleton for this component. The second parameter must be a unique bean name for the component. Add a dependency for this new bean into the application.
// Load the customized CSData for the application
addSingleton("ADF.apps.myApp.lib.csData_1_0", "myApp_csData");
addConstructorDependency(appBeanName, "myApp_csData", "csdata");

Best practices

You don't have to override the entire component, you can add new methods and override existing methods pretty easily. Using the above example, lets say you wanted to modify just the "getStandardMetadata()" function so it would return more data than it does now. A sample of your csData_1_0 (located in the /myApp/components/lib/ directory) would look like this:

<cfcomponent displayname="CSData" extends="ADF.lib.csData.csData_1_0">
	
<cfproperty name="version" value="1_0_0">
<cfproperty name="type" value="singleton">
<cfproperty name="data" type="dependency" injectedBean="data_1_0">

<cffunction name="getStandardMetadata" access="public" returnType="query">
 {your changes here}
</cffunction>

</cfcomponent>

Notice how the value of the "extends" attribute is pointing to the csData_1_0 component loaded into the ADF and notice how there are no other methods in this component. By extending the original csData_1_0 component, you automatically gain all of the methods defined in that component - so you need not copy those in.

This allows you to take advantage of any changes made to csData_1_0 automatically.