Building ColdFusion components
245
•
The Super keyword lets a component that overrides a base component method execute the
original base component method. This technique lets your subclassed component override a
method without losing the ability to call the original version of the method.
The following sections describe these coding techniques in greater detail.
Using component inheritance
Component inheritance lets you import component methods and properties from one
component into another component. Inherited components share any component methods or
properties that they inherit from other components, and ColdFusion MX initializes instance data
in the parent CFC when you instantiate the CFC that extends it.
When using component inheritance, inheritance should define an
is a
relationship between
components. For example, a component named president.cfc inherits its methods and properties
from manager.cfc, which inherits its methods and properties from employee.cfc. In other words,
president.cfc
is a
manager.cfc; manager.cfc
is an
employee.cfc; and president.cfc
is an
employee.cfc.
When CFC B extends CFC A, CFC A is called the
base
or parent component; CFC B is called the
the
sub
or child component.
Note:
When you use a component that extends another component, the This scope is not available in
the base (parent) component. Therefore, any component that you extend must not access the
contents of the This scope. However, a component that extends another component, and is not itself
extended, has full access to the This scope.
To use component inheritance:
1
Open the corpQuery.cfc file, and modify the code so that it appears as follows, or create a new
corpQuery.cfc with the following contents:
<cfcomponent extends="appResources.components.tellTime">
<cffunction name="getEmp" returnType="query">
<cfargument name="lastName" required="yes">
<cfquery name="empQuery" datasource="ExampleApps" dbtype="ODBC">
SELECT LASTNAME, FIRSTNAME, EMAIL
FROM
tblEmployees
WHERE LASTNAME LIKE ’#arguments.lastName#’
</cfquery>
<cfif empQuery.recordcount LT 1>
<cfthrow
type="noQueryResult"
message="No results were found. Please try again.">
<cfelse>
<cfreturn empQuery>
</cfif>
</cffunction>
</cfcomponent>
In the example, the
cfcomponent
tag’s
extends
attribute points to the
tellTime
component.
2
If you do not already have a tellTime.cfc with a
getLocalTime
method, create one with the
following contents, in the same directory as the corpQuery.cfc:
<cfcomponent>
<cffunction name="getLocalTime">
<cfoutput>#TimeFormat(now())#</cfoutput>
</cffunction>
</cfcomponent>
Содержание COLDFUSION MX 61-DEVELOPING 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...