Difference between revisions of "Custom Application ADF Library Overrides"

From ADF Docs
Jump to: navigation, search
(Overview)
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 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 "components" directory (e.g. /myApp/components/lib)
 +
# Copy your ADF Library Component from its directory and place it int your /myApp/components/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:
  
'''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.
+
<cfcomponent extends="ADF.core.Base">
 +
 
 +
to:
 +
 
 +
<cfcomponent extends="ADF.lib.csData.csData_1_0">
 +
 
 +
== 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:
 +
 
 +
<pre>
 +
<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>
 +
</pre>
 +
 
 +
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.

Revision as of 00:55, 8 March 2010

Overview

You should have learned that you can "inject" ADF Library Components 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 "components" directory (e.g. /myApp/components/lib)
  2. Copy your ADF Library Component from its directory and place it int your /myApp/components/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">

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.