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.
Содержание ColdFusion MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...