1 Step RoboPDF, ActiveEdit, ActiveTest, Authorware, Blue Sky Software, Blue Sky, Breeze, Breezo, Captivate, Central,
ColdFusion, Contribute, Database Explorer, Director, Dreamweaver, Fireworks, Flash, FlashCast, FlashHelp, Flash Lite,
FlashPaper, Flex, Flex Builder, Fontographer, FreeHand, Generator, HomeSite, JRun, MacRecorder, Macromedia, MXML,
RoboEngine, RoboHelp, RoboInfo, RoboPDF, Roundtrip, Roundtrip HTML, Shockwave, SoundEdit, Studio MX, UltraDev,
and WebHelp are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or
in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within
this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be registered in
certain jurisdictions including internationally.
This product includes code licensed from RSA Data Security.
Third-Party Information
This guide contains links to third-party websites that are not under the control of Macromedia, and Macromedia is not
responsible for the content on any linked site. If you access a third-party website mentioned in this guide, then you do so at your
own risk. Macromedia provides these links only as a convenience, and the inclusion of the link does not imply that Macromedia
endorses or accepts any responsibility for the content on those third-party sites.
ColdFusion MX Developer’s Guide provides the tools needed to develop Internet applications using
Macromedia ColdFusion MX. This manual is intended for web application programmers who are
learning ColdFusion MX or wish to extended their ColdFusion MX programming knowledge. It
provides a solid grounding in the tools that ColdFusion MX provides to develop web
applications.
Because of the power and flexibility of ColdFusion MX, you can create many different types of
web applications of varying complexity. As you become more familiar with the material presented
in this manual, and begin to develop your own applications, you will want to refer to CFML Reference for details about various tags and functions.
This manual can to help anyone with a basic understanding of HTML learn to develop
ColdFusion MX applications. However, this manual is most useful if you have basic ColdFusion
experience, or have read Getting Started Building ColdFusion MX Applications. The Getting Started Building ColdFusion MX Applications manual provides an introduction to ColdFusion and helps
you develop the basic knowledge that will make using this manual easier.
Approaches to using this manual
This section describes approaches to using this manual for beginning ColdFusion developers,
developers with some experience who want to develop expertise, and advanced developers who
want to learn about the new and enhanced features of ColdFusion MX.
13
Beginning with ColdFusion
If you are learning ColdFusion, it might be most effective to read this manual in the following
order:
1.
Chapter 1, “Introducing ColdFusion MX” through Chapter 4, “Using Expressions and
Number Signs” to learn the basics of CFML.
2.
Chapter 19, “Introduction to Databases and SQL” through Chapter 21, “Updating Your
Database” to learn about using databases.
3.
Chapter 26, “Introduction to Retrieving and Formatting Data” and Chapter 27, “Building
Dynamic Forms with cfform Tags” to learn about requesting data from users.
After you read these chapters, you should have a basic understanding of the basic elements of
ColdFusion, and be able to create simple ColdFusion applications. To learn to produce more
complete and robust applications, you could proceed with the following chapters:
4.
Chapter 13, “Designing and Optimizing a ColdFusion Application” through Chapter 18,
“Debugging and Troubleshooting Applications” to learn how to build a complete ColdFusion
application.
5.
Chapter 22, “Using Query of Queries” to learn how to use queries effectively.
6.
Chapter 5, “Using Arrays and Structures” through Chapter 10, “Building and Using
ColdFusion Components” to learn to use more advanced features of CFML, including ways to
reuse code.
You can then read the remaining chapters as you add new features to your ColdFusion
application.
Developing an in-depth knowledge of ColdFusion
If you have a basic understanding of ColdFusion as presented in Getting Started Building
ColdFusion MX Applications or the Fast Track to ColdFusion course, you might want to start at
Chapter 1 and work through to the end of the book, skipping any specialized chapters that you
are unlikely to need.
Learning about new and modified ColdFusion features
If you are an advanced ColdFusion developer, you might want to learn about new or changed
ColdFusion features. The following chapters document features that are new or substantially
enhanced in ColdFusion MX 7:
• Chapter 24, “Building a Search Interface”
• Chapter 25, “Using Verity Search Expressions”
• Chapter 27, “Building Dynamic Forms with cfform Tags”
• Chapter 28, “Validating Data”
• Chapter 29, “Creating Forms in Macromedia Flash”
• Chapter 30, “Creating Skinnable XML Forms”
• Chapter 32, “Creating Reports for Printing”
14Introduction: About ColdFusion MX Documentation
• Chapter 42, “Using Event Gateways”
• Chapter 43, “Using the Instant Messaging Event Gateways”
• Chapter 44, “Using the SMS Event Gateway”
• Chapter 45, “Creating Custom Event Gateways”
Nearly all chapters contain information that is new in ColdFusion MX 7, so you should also
review all other chapters for useful information. The index and the table of contents are useful
tools for finding new features or changed documentation.
Note: If you are moving from ColdFusion 4.5 or 5, start by reading Migrating ColdFusion 5
Applications, available on the Macromedia website.
ColdFusion features described in this manual
ColdFusion provides a comprehensive set of features for developing and managing Internet
applications. These features enhance speed and ease-of-development, and let you dynamically
deploy your applications, integrate new and legacy technologies, and build secure applications.
The following table describes the primary ColdFusion features that are discussed in this manual,
and lists the chapters that describe them. This table is only a summary of major CFML features;
this manual also includes information about other features. Also, this table does not include
features that are described in other manuals.
FeatureDescriptionChapters
CFMLCFML is a fully featured tag-oriented Internet application language.
It includes a wide range of tags, functions, variables, and
expressions.
CFScriptCFScript is a server-side scripting language that provides a subset
of ColdFusion functionality in script syntax.
Regular
expressions
Reusable
elements
User-defined
functions
(UDFs)
ColdFusion
components
Custom CFML
tags
ColdFusion
extension (CFX)
tags
ColdFusion provides several functions that use regular expressions
for string manipulation. It also lets you use regular expressions in
text input tags.
ColdFusion lets you create several types of elements, such as userdefined functions and ColdFusion components, that you write once
and can use many times.
You can use CFScript or the
functions. These functions can incorporate all of the built-in
ColdFusion tags and functions, plus other extensions.
ColdFusion components encapsulate multiple functions and
related data in a single logical unit. ColdFusion components can
have many uses, and are particularly useful in creating web services
and Flash interfaces for your application.
You can create custom ColdFusion tags using CFML. These tags
can have bodies and can call other custom tags.
You can create custom tags in Java or C++. These tags can use
features that are only available when using programming
languages. However, CFX tags cannot have tag bodies.
cffunction tag to create your own
2–5
6
7, 28
8–12
9
10
11
12
Using this manual15
FeatureDescriptionChapters
ColdFusion
application
structure
ColdFusion supports many ways of building an application, and
includes specific features, such as the Application.cfc file or
Application.cfm page, built-in security features, and shared scopes,
13–17
that help you optimize your application structure.
Error handling
mechanisms
Shared and
persistent variable
scopes
Code lockingYou lock sections of code that access in-memory shared scopes or
ColdFusion provides several mechanisms for handling data,
including custom error pages and exception-handling tags and
functions, such as
cftry and cfcatch.
Using shared and persistent scopes, you can make data available to
a single user over one or many browser sessions, or to multiple
users of an application or server.
14
15
15
use external resources that are not safe for multiple simultaneous
access.
Application
security
ColdFusion provides mechanisms, including the
cflogin tag, for
authenticating users and authorizing them to access specific
16
sections of your application. You can also use resource security,
which secures access to ColdFusion resources based on the
ColdFusion page location.
Application
globalization
ColdFusion supports global applications that use different
character sets and locales, and provides tags and functions
17
designed to support globalizing your applications.
Debugging toolsUsing debugging output, the
cftrace tag, logging features, and the
18
Code Analyzer, you can locate and fix coding errors.
Database access
and management
ColdFusion can access SQL databases to retrieve, add, and modify
data. This feature is one of the core functions of many dynamic
19–21
applications.
Queries of Queries You can use a subset of standard SQL within ColdFusion to
22
manipulate any data that is represented as a record set, including
database query results, LDAP (Lightweight Directory Access
Protocol) directory information, and other data.
LDAP directory
access and
management
Indexing and
searching data
ColdFusion applications can access and manipulate data in LDAP
directory services. These directories are often used for security
validation data and other directory-like information.
ColdFusion applications can provide full-text search capabilities for
documents and data sources using the Verity search engine.
Dynamic formsWith ColdFusion, you can use HTML and forms to control the data
displayed by a dynamic web page. You can also use the
cfform tag
23
24–25
26–30
to enrich your forms with sophisticated graphical controls, and
perform input data validation.
Validating dataColdFusion provides several ways to validate data in forms and in
28
CFML variables.
Flash formsColdFusion can display forms using Macromedia Flash, which
29
presents a pleasing appearance and includes features such as
accordion and tab navigators.
16Introduction: About ColdFusion MX Documentation
FeatureDescriptionChapters
XML skinnable
forms
Data graphingYou can use the
Reports and
printable output
ColdFusion can convert your CFML forms into XML and format the
XML using XSLT skins and style sheets.
cfchart tag to display your data graphically.31
You can create output that is formatted for print as PDF or
FlashPaper documents. You can also use ColdFusion reporting to
30
32
create banded reports for display or printing.
Macromedia Flash
integration
Server-side
ActionScript
You can use native Flash connectivity built into ColdFusion to help
build dynamic Flash user interfaces for ColdFusion applications.
directly access ColdFusion query and HTTP features through two
XML document
processing and
creation
functions:
ColdFusion applications can create, use, and manipulate XML
(Extensible Markup Language) documents. ColdFusion also
provides tools to use WDDX (Web Distributed Data Exchange), an
CF.query and CF.http.
35
XML dialect for transmitting structured data.
Web servicesColdFusion applications can use available SOAP (Simple Object
36
Access Protocol)-based web services, including Microsoft .NET
services. ColdFusion applications can also use ColdFusion
components to provide web services to other applications over the
Internet.
Java and J2EE
integration
You can integrate J2EE elements, including JSP (JavaServer
Pages) pages, JSP tag libraries, and Java objects, including EJBs
37
(Enterprise JavaBeans), into your ColdFusion application.
COM and CORBA
objects
The
cfobject tag lets you use COM (Component Object Model) or
DCOM (Distributed Component Object Model) and CORBA
38
(Common Object Request Broker) objects in your ColdFusion
applications.
E-mail messages You can add interactive e-mail features to your ColdFusion
applications using the
HTTP and FTPThe
cfhttp and cfftp tags provide simple methods of using HTTP
cfmail and cfpop tags.
39
40
(Hypertext Transfer Protocol) and FTP (File Transfer Protocol)
communications in your application.
File and directory
access
Event gatewaysColdFusion event gateways let ColdFusion applications
You can use the
cffile, cfdirectory, and cfcontent tags to read,
write, and manage files and directories on the server.
41
42–45
asynchronously react to or generate external events or messages.
Instant messaging
event gateways
Your ColdFusion application can communicate with XMPP
(Jabber) or IBM Sametime instant messaging clients using the
43
ColdFusion IM gateways.
Using this manual17
FeatureDescriptionChapters
SMS event
gateway
Creating gateways You can write your own event gateways in Java and integrate them
Your ColdFusion MX application can communicate with short
message service (SMS) devices, such as mobile phones, using the
ColdFusion SMS event gateway.
into ColdFusion MX.
Accessing the ColdFusion MX documentation
The ColdFusion MX documentation is designed to provide support for the complete spectrum of
participants.
Documentation set
The ColdFusion MX 7 documentation set includes the following titles:
BookDescription
Installing and Using
ColdFusion MX
Configuring and
Administering
ColdFusion MX
ColdFusion MX
Developer’s Guide
Getting Started
Building
ColdFusion MX
Applications
CFML Reference Provides descriptions, syntax, usage, and code examples for all ColdFusion
CFML Quick Reference Provides a brief guide that shows the syntax of ColdFusion tags, functions,
Describes system installation and basic configuration for Windows, Solaris,
and Linux. To see this manual, go to www.macromedia.com/go/
livedocs_cfmx7docs_installing.
Part I describes how to manage the ColdFusion environment, including
connecting to your data sources and configuring security for your
applications. Part II describes Verity search tools and utilities that you can
use for configuring the Verity Search Server engine, as well as creating,
managing, and troubleshooting Verity collections. To see this manual, go to
Describes how to develop your dynamic web applications, including
retrieving and updating your data, using structures, and forms. This manual
includes two volumes. To see this manual, go to www.macromedia.com/go/
livedocs_cfmx7docs_dev.
Contains an overview of ColdFusion features and application development
procedures. Includes a tutorial that guides you through the process of
developing an example ColdFusion application. To see this manual, go to
www.macromedia.com/go/livedocs_cfmx7docs_gs.
tags, functions, and variables. This manual includes two volumes. To see
this manual, go to www.macromedia.com/go/
livedocs_cfmx7docs__cfml_reference.
and variables.
44
45
Viewing online documentation
All ColdFusion MX documentation is available online in HTML and Adobe Acrobat Portable
Document Format (PDF) files. Go to the documentation home page for ColdFusion MX on the
Macromedia website: www.macromedia.com.
18Introduction: About ColdFusion MX Documentation
CHAPTER 1
Introducing ColdFusion MX
This chapter describes Macromedia ColdFusion MX and the role it plays in developing dynamic
Internet applications. This chapter also introduces the topics discussed in this manual.
Contents
About Internet applications and web application servers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
About Internet applications and web application servers
With ColdFusion MX, you develop Internet applications that run on web application servers.
The following sections introduce Internet applications and web application servers. Later sections
explain the specific role that ColdFusion MX plays in this environment.
About web pages and Internet applications
The Internet has evolved from a collection of static HTML pages to an application deployment
platform. First, the Internet changed from consisting of static web pages to providing dynamic,
interactive content. Rather than providing unchanging content where organizations merely
advertise goods and services, dynamic pages enable companies to conduct business ranging from
e-commerce to managing internal business processes. For example, a static HTML page lets a
bookstore publish its location, list services such as the ability to place special orders, and advertise
upcoming events like book signings. A dynamic website for the same bookstore lets customers
order books online, write reviews of books they read, and even get suggestions for purchasing
books based on their reading preferences.
More recently, the Internet has become the underlying infrastructure for a wide variety of
applications. With the arrival of technologies such as XML, web services, J2EE (Java 2 Platform,
Enterprise Edition), and Microsoft .NET, the Internet has become a multifaceted tool for
integrating business activities. Now, enterprises can use the Internet to integrate distributed
activities, such as customer service, order entry, order fulfillment, and billing.
19
ColdFusion MX is a rapid application development environment that lets you build dynamic
websites and Internet applications quickly and easily. It lets you develop sophisticated websites
and Internet applications without knowing the details of many complex technologies, yet it lets
advanced developers take advantage of the full capabilities of many of the latest Internet
technologies.
About web application servers
To understand ColdFusion, you must first understand the role of web application servers.
Typically, web browsers make requests, and web servers, such as Microsoft Internet Information
Server (IIS) and the Apache web server, fulfill those requests by returning the requested
information to the browser. This information includes, but is not limited to, HTML and
Macromedia Flash files.
A web server’s capabilities are limited because all it does is wait for requests to arrive and attempt
to fulfill those requests as soon as possible. A web server does not let you do the following tasks:
• Interact with a database, other resource, or other application.
• Serve customized information based on user preferences or requests.
• Validate user input.
A web server, basically, locates information and returns it to a web browser.
To extend the capabilities of a web server, you use a web application server, a software program that
extends the web server’s capabilities to do tasks such as those in the preceding list.
20Chapter 1: Introducing ColdFusion MX
How a web server and web application server work together
The following steps explain how a web server and web application server work together to process
a page request:
1.
The user requests a page by typing a URL in a browser, and the web server receives the request.
2.
The web server looks at the file extension to determine whether a web application server must
process the page. Then, one of the following actions occur:
■ If the user requests a file that is a simple web page (often one with an HTM or HTML
extension), the web server fulfills the request and sends the file to the browser.
■ If the user requests a file that is a page that a web application server must process (one with
a CFM, CFML, or CFC extension for ColdFusion requests), the web server passes the
request to the web application server. The web application server processes the page and
sends the results to the web server, which returns those results to the browser. The following
figure shows this process:
1
Web browser
requests
a web page.
2
Web server
receives the
page request.
3
Web server instructs
application server
to process the page.
4
The application server
processes the page
and generates output.
5
The web server
sends the output
to the browser.
Because web application servers interpret programming instructions and generate output that a
web browser can interpret, they let web developers build highly interactive and data-rich websites,
which can do tasks such as the following:
• Query other database applications for data.
• Dynamically populate form elements.
• Dynamically generate Flash application data.
• Provide application security.
• Integrate with other systems using standard protocols such as HTTP, FTP, LDAP, POP,
and SMTP.
• Create shopping carts and e-commerce websites.
• Respond with an e-mail message immediately after a user submits a form.
• Return the results of keyword searches.
About Internet applications and web application servers21
About ColdFusion MX
ColdFusion MX is a rapid scripting environment server for creating dynamic Internet
Applications. ColdFusion Markup Language (CFML) is an easy-to-learn tag-based scripting
language, with connectivity to enterprise data and powerful built-in search and charting
capabilities. ColdFusion MX enables developers to easily build and deploy dynamic websites,
content publishing systems, self-service applications, commerce sites, and more.
ColdFusion MX consists of the following core components:
• ColdFusion scripting environment
• CFML
• ColdFusion MX Administrator
• Verity Search Server
The following sections describe these core components in more detail.
The ColdFusion scripting environment
The ColdFusion scripting environment provides an efficient development model for Internet
applications. At the heart of the ColdFusion scripting environment is the ColdFusion Markup
Language (CFML), a tag-based programming language that encapsulates many of the low-level
details of web programming in high-level tags and functions.
ColdFusion Markup Language
ColdFusion Markup Language (CFML) is a tag-based language, similar to HTML, that uses
special tags and functions. With CFML, you can enhance standard HTML files with database
commands, conditional operators, high-level formatting functions, and other elements to rapidly
produce easy-to-maintain web applications. However, CFML is not limited to enhancing
HTML. For example, you can create Macromedia Flash MX applications that consist entirely of
Flash elements and CFML. Similarly, you can use CFML to create web services for use by other
applications.
The following sections briefly describe basic CFML elements. For more information, see
Chapter 2, “Elements of CFML,” on page 27.
CFML tags
CFML looks similar to HTML—it includes starting and, in most cases, ending tags, and each tag
is enclosed in angle brackets. All ending tags are preceded with a forward slash (/) and all tag
names are preceded with
<cftagname>
tag body text and CFML
</cftagname>
cf; for example:
CFML increases productivity by providing a layer of abstraction that hides many low-level details
involved with Internet application programming. At the same time, CFML is extremely powerful
and flexible. ColdFusion lets you easily build applications that integrate files, databases, legacy
systems, mail servers, FTP servers, objects, and components.
22Chapter 1: Introducing ColdFusion MX
CFML includes approximately 110 tags. ColdFusion tags serve many functions. They provide
programming constructs, such as conditional processing and loop structures. They also provide
services, such as charting and graphing, full-text search, access to protocols such as FTP, SMTP/
POP, and HTTP, and much more. The following table lists a few examples of commonly used
ColdFusion tags:
TagPurpose
cfquery
cfoutput
cfset
cfmail
cfchart
cfobject
Establishes a connection to a database (if one does not exist), executes a query, and
returns results to the ColdFusion environment.
Displays output that can contain the results of processing ColdFusion functions,
variables, and expressions.
Sets the value of a ColdFusion variable.
Lets an application send SMTP mail messages using application variables, query
results, or server files. (Another tag,
Converts application data or query results into graphs, such as bar charts or pie charts,
in Flash, JPG, or PNG format.
Invokes objects written in other programming languages, including COM (Component
Object Model) components, Java objects such as Enterprise JavaBeans, or Common
CORBA (Object Request Broker Architecture) objects.
cfpop, gets mail.)
CFML Reference describes the CFML tags in detail.
CFML functions and CFScript
CFML includes approximately 280 built-in functions. These functions perform a variety of roles,
including string manipulation, data management, and system functions. CFML also includes a
built-in scripting language, CFScript, that lets you write code in a manner that is familiar to
programmers and JavaScript writers.
CFML extensions
You can extend CFML further by creating custom tags or user-defined functions (UDFs), or by
integrating COM, C++, and Java components (such as JSP tag libraries). You can also create
ColdFusion components (CFCs), which encapsulate related functions and properties and provide
a consistent interface for accessing them.
All these features let you easily create reusable functionality that is customized to the types of
applications or websites that you are building.
CFML development tools
Macromedia Dreamweaver MX 2004 helps you develop ColdFusion applications efficiently. It
includes many features that simplify and enhance ColdFusion development, including tools for
debugging CFML. Because CFML is written in an HTML-like text format, and you often use
HTML in ColdFusion pages, you can also use an HTML editor or a text editor, such as Notepad,
to write ColdFusion applications.
About ColdFusion MX23
Verity Search Server
The Verity Search Server (also called the Verity search engine) provides full text search capability
for documents and data on a ColdFusion MX site.
ColdFusion MX Administrator
ColdFusion MX Administrator configures and manages the ColdFusion application server. It is a
secure web-based application that you can access using any web browser, from any computer with
an Internet connection.
For more information about ColdFusion MX Administrator, see Configuring and Administering ColdFusion MX.
About J2EE and the ColdFusion architecture
As the Internet software market has matured, the infrastructure services required by distributed
Internet applications, including ColdFusion applications, have become increasingly standardized.
The most widely adopted standard today is the Java 2 Platform, Enterprise Edition (J2EE)
specification. J2EE provides a common set of infrastructure services for accessing databases,
protocols, and operating system functionality, across multiple operating systems.
About ColdFusion MX and the J2EE platform
ColdFusion MX is implemented on the Java technology platform and uses a J2EE application
server for many of its base services, including database connectivity, naming and directory
services, and other runtime services. ColdFusion MX can be configured to use an embedded J2EE
server (in the server configuration) or it can be deployed as a J2EE application on an independent
J2EE application server (in the multiserver configuration or the J2EE configuration). ColdFusion
MX Enterprise includes a fully featured version of the Macromedia JRun J2EE application server,
or can be deployed on third-party J2EE servers such as IBM WebSphere and BEA WebLogic.
For more information on ColdFusion MX configurations, see Installing and Using ColdFusion MX.
By implementing the ColdFusion scripting environment on top of the J2EE platform,
ColdFusion MX takes advantage of the power of the J2EE platform while also providing an easyto-use scripting environment and built-in services. Moreover, because ColdFusion is built on a
J2EE platform, you can easily integrate J2EE and Java functionality into your ColdFusion
application. As a result, ColdFusion pages can do any of the following:
• Share session data with JSPs (Java Server Pages) and Java servlets.
• Import custom JSP tag libraries and use them like ColdFusion custom tags.
• Integrate with Java objects, including the J2EE Java API, JavaBeans, and Enterprise JavaBeans.
For more information on using J2EE features in ColdFusion, see Chapter 37, “Integrating J2EE
and Java Elements in CFML Applications,” on page 917.
24Chapter 1: Introducing ColdFusion MX
PART I
The CFML Programming Language
This part describes the elements of the CFML programming language. It tells you how to use
CFML tags, functions, variables and expressions, the CFScript scripting language, and regular
expressions.
This chapter provides an overview of the basic elements of CFML, including tags, functions,
constants, variables, expressions, and CFScript. The chapters in Part I of this manual describe
these topics in detail.
This chapter introduces and describes the basic elements of CFML. These elements make CFML
a powerful tool for developing interactive web applications. Because CFML is a dynamic
application development tool, it has many of the features of a programming language, including
the following:
• Functions
• Expressions
• Variables and constants
• Flow-control constructs such as if-then and loops
CFML also has a “language within a language,” CFScript, which enables you to use a syntax
similar to JavaScript for many operations.
This chapter introduces these elements and other basic CFML entities such as comments, data
types, escape characters, and reserved words.
The remainder of Part I of this manual provides more detailed information on many of the basic
CFML elements. The rest of this manual helps you use these elements effectively in your
applications.
Comments
ColdFusion comments have a similar format to HTML comments. However, they use three dash
characters instead of two; for example:
<!--- This is a ColdFusion Comment. Browsers do not receive it. --->
The ColdFusion server removes all ColdFusion comments from the page before returning it to
the web server. As a result, the page that a user browser receives does not include the comment,
and users cannot see it even if they view the page source.
You can embed CFML comments in begin tags (not just tag bodies), functions calls, and variable
text in number signs. ColdFusion ignores the text in comments such as the following:
This is useful if you want to temporarily disable a section of code while you test your application.
You can embed comments within comments, however, you should use this technique carefully.
28Chapter 2: Elements of CFML
Note: You cannot embed comments inside a tag name or function name, such as
<cf_My<!--- New --->CustomTag>. You also cannot embed comments inside strings, as in the
following example:
IsDefined("My<!--- New --->Variable").
Tags
ColdFusion tags tell the ColdFusion server that it must process information. The ColdFusion
server only processes tag contents; it returns text outside of ColdFusion to the web server
unchanged. Macromedia ColdFusion MX provides a wide variety of built-in tags and lets you
create custom tags.
Tag syntax
ColdFusion tags have the same format as HTML tags. They are enclosed in angle brackets
(< and >) and can have zero or more named attributes. Many ColdFusion tags have bodies; that
is, they have beginning and end tags with text to be processed between them. For example:
<cfoutput>
Hello #YourName#! <br>
</cfoutput>
Other tags, such as cfset and cfftp, never have bodies; all the required information goes
between the beginning (<) character and the ending (>) character, as in the following example:
<cfset YourName="Bob">
Sometimes, although the tag can have a body, you do not need to put anything in it because the
attributes specify all the required information. You can omit the end tag and put a forward slash
character before the closing (>) character, as in the following example:
Note: The
tag encloses an assignment statement that assigns a value to a variable. The
function without assigning a value to a result variable.
cfset tag differs from other tags in that it has neither a body nor arguments. Instead, the
cfset tag can also call a
Built-in tags
Over 110 built-in tags make up the heart of ColdFusion. These tags have many uses, including
the following:
• Manipulating variables
• Creating interactive forms
• Accessing and manipulating databases
• Displaying data
• Controlling the flow of execution on the ColdFusion page
• Handling errors
• Processing ColdFusion pages
• Managing the CFML application framework
• Manipulating files and directories
Tags29
• Using external tools and objects, including Verity collections, COM, Java, and CORBA
objects, and executable programs
• Using protocols, such as mail, http, ftp, and pop
Much of this document describes how to use these tags effectively. CFML Reference documents
each tag in detail.
Custom tags
ColdFusion lets you create custom tags. You can create two types of custom tags:
• CFML custom tags that are ColdFusion pages
• CFX tags that you write in a programing language such as Java or C++
Custom tags can encapsulate frequently used business logic or display code. These tags enable you
to place frequently used code in one place and call it from many places. Custom tags also let you
abstract complex logic into a single, simple interface. They provide an easy way to distribute your
code to others; you can even distribute encrypted versions of the tags to prevent access to the tag
logic.
You can access a variety of free and commercial custom tags on the Macromedia developer’s
exchange (www.macromedia.com/cfusion/exchange/index.cfm). They perform tasks ranging
from checking if Cookies and JavaScript are enabled on the client's browser to moving items from
one list box to another. Many of these tags are free and include source code.
CFML custom tags
When you write a custom tag in CFML, you can take advantage of all the features of the
ColdFusion language, including all built-in tags and even other custom tags. CFML custom tags
can include body sections and end tags. Because they are written in CFML, you do not need to
know a programming language such as Java. CFML custom tags provide more capabilities than
user-defined functions, but are less efficient.
For more information on CFML custom tags, see Chapter 11, “Creating and Using Custom
CFML Tags,” on page 241. For information about, and comparisons among, ways to reuse
ColdFusion code, including CFML custom tags, user-defined functions, and CFX tags, see
Chapter 8, “Creating ColdFusion Elements,” on page 161.
CFX Tags
CFX tags are ColdFusion custom tags that you write in a programming language such as Java or
C++. These tags can take full advantage of all the tools and resources provided by these languages,
including their access to runtime environments. CFX tags also generally execute faster than
CFML custom tags because they are compiled. CFX tags can be cross-platform, but are often
platform-specific, for example if they take advantage of COM objects or the Windows API.
For more information on CFX tags, see Chapter 12, “Building Custom CFXAPI Tags,” on
page 259.
30Chapter 2: Elements of CFML
Loading...
+ 1110 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.