Using ColdFusion MX Tags


Tags are the main building blocks of CFML and enable you to perform various tasks, such as data manipulation and output display. Before we go into the specific details of CFML tags, you need to understand how a Web browser processes these tags. Conventionally, CFML files have the .cfm extension. It's possible to have an extension other than .cfm, provided you configure the Web server to associate the new extension with the ColdFusion engine. Another extension is .cfc, for ColdFusion components. When a Web browser requests a .cfm file, the ColdFusion application server first interprets all the CFML tags. After the tags are interpreted, the ColdFusion server returns an HTML document to the Web server, which is then displayed in the browser window. CFML tags are processed sequentially until the end of the file is reached; non-CFML tags are ignored during the processing.

Each CFML tag has a start tag and an end tag, <CF TagName> and </CF TagName>, respectively. Note that the end tag is identified by a slash (/). CFML tags accept one or more attributes, which allow you to pass values to the tag for processing. For example, the <CFMAIL> tag uses attributes in the following manner:

 <!--- This is a comment ---> <CFMAIL FROM="you@your.domain"       TO="myself@my.domain"       SUBJECT="Here is an example"> My Test Message </CFMAIL> 

The preceding code begins with a CFML comment. The CFML comments follow these conventions:

  • CFML comments contain three dashes.

  • There's a space between the opening and closing marker and the text of the comment.

The <CFMAIL> tag takes three attributes: FROM, TO, and SUBJECT. In addition to these attributes, there are other optional attributes that further affect its behavior. These optional attributes force the tag to discard the default values and take new values. For example, to specify the server name or IP address of the mail server, the SERVER optional attribute is used as follows:

 <!--- This is a comment ---> <CFMAIL FROM="you@your.domain"      TO="myself@my.domain"      SUBJECT="Here is an example"      SERVER="111.0.0.1"> My Test Message </CFMAIL> 

The attributes have been assigned literal values within double quotes. Instead of literal values, you can use expressions, which are discussed later in this chapter. The text enclosed within the start and end tags, My Test Message, is displayed on the page in the browser window.

Similar to HTML, CFML has a number of built-in tags. One of the basic tags is <CFSET>, which is used to create a variable, a named location in computer memory. (Variables are covered in detail later in this chapter.) For example, the following code creates a variable named Quantity, which is assigned the value 100:

 <CFSET Quantity = 100> 

Note

It's not necessary to enclose literal values within double quotes when referring to numeric values, Boolean values, or expressions.

Some of the other important CFML tags are summarized in Table 2.1. The complete list of CFML tags and their functions can be obtained from the CFML reference manual.

Table 2.1: Common CFML Tags and Their Functions

Tag Name

Function

<CFQUERY>

Establishes a connection to a database, executes a query, and returns the results to the ColdFusion environment

<CFOUTPUT>

Displays the output, which can be the result of processing ColdFusion functions, variables, or expressions

<CFMAIL>

Enables an application to send SMTP (Simple Mail Transfer Protocol) mail messages using application variables, query results, or server files

<CFCHART>

Converts the application data or query results into graphs, such as bar charts or pie charts, in Flash, JPG, or PNG format

<CFOBJECT>

Invokes objects written in other programming languages, including COM (Component Object Model) components, Java objects such as Enterprise JavaBeans, or CORBA (Common Object Request Broker Architecture) objects

Unlike HTML, ColdFusion allows you to create your own custom tags, which are used to develop portable code that can be used across programs. They provide an easy method to distribute your code. You can distribute encrypted versions of the tags to others to prevent access to the tag logic. Currently, over 1,000 custom tags are available on Macromedia's developer site.

Custom tags can be created using CFML or an external programming language, such as Java. Custom tags created using CFML are referenced as CF_TagName, whereas custom tags created using an external programming language are referenced as CFX_TagName. For further details on creating custom tags, refer to Appendix A, "Creating ColdFusion MX Custom Tags."




Macromedia ColdFusion MX. Professional Projects
ColdFusion MX Professional Projects
ISBN: 1592000126
EAN: 2147483647
Year: 2002
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net