246
Chapter 11: Building and Using ColdFusion Components
3
Create a ColdFusion page with the following code, and save it as inherit.cfm in your web root
directory:
<cfinvoke component="corpQuery" method="getEmp" lastName="gilson">
<cfinvoke component="corpQuery" method="getLocalTime">
When you execute the inherit.cfm file, the
getLocalTime
component method executes even
though it is invoked using the corpQuery component.
Using component.cfc
All CFCs automatically extend the ColdFusion WEB-INF\cftags\component.cfc component.
(WEB-INF is in the
cf_root
/wwwroot directory on ColdFusion configured with an embedded
J2EE server. It is in the
cf_root
directory when you deploy ColdFusion on a J2EE server.) This
CFC is distributed as a zero-length file. You can use it for any core methods or properties that you
want
all
CFCs in your ColdFusion application server instance to inherit.
Using the Super keyword
You use the
Super
keyword only on CFCs that use the Extends attribute to extend another CFC.
Unlike ColdFusion scopes, it is
not
used for variables; it is only used for CFC methods, and it is
not available on ColdFusion pages that invoke CFCs.
The Super keyword lets you refer to original, base component, versions of methods that the
current component extends. Therefore if CFC B extends CFC A, and CFC B overrides some of
the methods in CFC A, CFC B can use the original versions of the overridden methods, as
defined in CFC A, by prefixing the method name with Super.
For example, assume the following:
•
CFC B extends CFC A.
•
CFC A defines a Remove method that removes spaces from text.
•
CFC B defines a Replace method that removes invalid characters.
With these functions, in CFC B, you can invoke
Replace(StringVar="some str%^ing")
to
replace invalid characters in your text. CFC B could call
Super.Replace(StringVar=Arguments.StringVar)
to remove the spaces before removing
other invalid characters.
Included pages can use the Super keyword.
Super keyword limitations
The following limitations apply to the use of the Super keyword:
•
The Super keyword supports only one level of inheritance. If you use multiple levels of
inheritance, you can only use the Super keyword to access the current component’s immediate
parent. For example, if C.cfc extends B.cfc and B.cfc extends A.cfc, you can use Super.myFunc
in C.cfc to invoke the version of myFunc that is defined in B.cfc. You cannot use
Super.Super.cfc to invoke the version of myFunc that is defined in A.cfc. To get around this
limitation, you could define a super_MyFunc method in B.cfc that invokes Super.myFunc.
The C.cfc could then invoke Super.super_MyFunc.
•
Because base components do not have access to the This scope, you cannot use the Super
keyword for any method that uses a variable in the This scope.
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......