
170
Chapter 8: Reusing Code in ColdFusion Pages
Recommended uses
CFX tags provide one way of using C++ or Java code. However, you can also create Java classes
and COM objects and access them using the
cfobject
tag. CFX tags, however, provide some
built-in features that the
cfobject
tag does not have:
•
CFX tags are easier to call in CFML code. You use CFX tags directly in CFML code as you
would any other tag, and you can pass arguments using a standard tag format.
•
ColdFusion provides predefined classes for use in your Java or C++ code that facilitate CFX tag
development. These classes include support for request handling, error reporting, and query
management.
You should consider using CFX tags in the following circumstances:
•
You already have existing application functionality written in C++ or Java that you want to
incorporate into your ColdFusion application.
•
You cannot build the functionality you need using ColdFusion elements.
•
You want to provide the new functionality in a tag format, as opposed to using the
cfobject
tag to import native Java or COM objects.
•
You want use the Java and C++ classes provided by ColdFusion for developing your CFX code.
For more information
For more information on CFX tags, see
Chapter 12, “Building Custom CFXAPI Tags,”
on page 251
.
Using ColdFusion components
Unlike other Coldfusion reusable elements, ColdFusion components encapsulate multiple,
related, functions. A
ColdFusion component
is essentially a set of related UDFs and variables, with
additional functionality to provide and control access to the component contents. ColdFusion
components can make their data private, so that it is available to all functions (also called
methods) in the component, but not to any application that uses the component.
ColdFusion components have the following features:
•
They are designed to provide related services in a single unit.
•
They can provide web services and make them available over the internet.
•
They can provide ColdFusion services that Macromedia Flash clients can call directly.
•
They have several features that are familiar to object-oriented programmers including data
hiding, inheritance, packages, and introspection.
Creating and using ColdFusion components
Creating and using a component is more complex than creating and using a user-defined function
(UDF). For example, you specify a component and one or more functions. You can invoke
ColdFusion components in many ways, including using the
cfinvoke
and
cfobject
tags. You
can also use forms, URLs, and the Flash client-side ActionScript.
To invoke a component method with a
cfinvoke
tag, use code such as the following:
<cfinvoke component="componentName" method="methodName"
returnVariable="variableName" argumentCollection="argumentStruct">
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: ......