228
Chapter 11: Building and Using ColdFusion Components
Using cfinvoke within the CFC definition
You can use the
cfinvoke
tag to invoke a component method within the component definition;
for example, to call a utility method that provides a service to other methods in the component.
To use
cfinvoke
in this instance, do not create an instance or specify the component name in the
cfinvoke
tag, as the following example shows:
<cfinvoke method="getLocalTime">
Passing parameters to methods using cfinvoke
When you use the
cfinvoke
tag, ColdFusion MX provides several methods for passing
parameters to CFC methods:
•
As
cfinvoke
tag attributes, in name="value" format
•
In the
cfinvoke
tag
argumentcollection
attribute
•
In the
cfinvoke
tag body, using
cfinvokeargument
tag
You can use any combination of these methods in a single invocation. If you use the same name in
two or three of these methods, ColdFusion uses the value based on the following order of
precedence:
1
cfinvokeargument
tags
2
cfinvoke
attribute name-value pairs
3
argumentcollection
arguments
Passing parameters using attribute format
You can pass parameters in the
cfinvoke
tag as tag attribute name-value pairs, as the following
example shows:
<cfinvoke component="authQuery" method="getAuthSecure"
lastName="#session.username#" password="#url.password#">
In the example, the parameters are passed as the
lastName
and
password
attributes.
Note:
The
cfinvoke
tag attribute names are reserved and cannot be used for parameter names. The
reserved attribute names are:
component
,
method
,
argumentCollection
, and
returnVariable
. For more
information, see
CFML Reference
.
Passing parameters in the argumentCollection attribute
If you save attributes to a structure, you can pass the structure directly using the
cfinvoke
tag’s
argumentCollection
attribute. This technique is useful if an existing structure or scope (such as
the Forms scope) contains values that you want to pass to a CFC as parameters, and for using
conditional or looping code to create parameters.
When you pass an argumentCollection structure, each structure key is the name of a parameter
inside the structure.
The following example passes the Form scope to the
addUser
method of the UserDataCFC. In
the method, each form field name is a parameter name. Then the method can use the contents of
the form fields to add a user to a database.
<cfinvoke component="UserDataCFC" method="addUser"
argumentCollection="#Form#">
Содержание 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...