Chapter 17. Introducing ColdFusion MX 7

In this chapter

Introducing ColdFusion MX 7

The term ColdFusion has definitely become a popular buzzword in the web community over the last five years or so. If you haven’t ever heard of ColdFusion, you might be wondering whether Macromedia has discovered a way to derive incredible amounts of power from a single glass of salt water and has, somehow, done it using the web. Although Macromedia’s version of ColdFusion doesn’t have anything to do with salt water, it has a lot to do with power and the web.

ColdFusion is one of several dynamic server infrastructures (or “platforms”) that enables you to extract data from a database and display it in your web pages. Other dynamic platforms include Active Server Pages (ASP), ASP.NET, Java Server Pages (JSP), and Hypertext PreProcessor (PHP). What sets ColdFusion apart from these other platforms is that it is extremely easy to learn, easy to use, and as powerful as any of the other platforms.

The developer version of ColdFusion, included with Studio 8, enables you to develop ColdFusion applications and run them strictly on your development machine. This limitation is enforced by the fact that the server can be accessed by only one additional IP address—just enough for testing.

You need a production ColdFusion server to make your applications available on the web. You can either buy and manage your own production ColdFusion server or pay a monthly fee for a hosting service—the same options you have for an ordinary website. You may also be able to find free ColdFusion hosting, which may be appropriate for testing or for non-critical uses that don’t put much stress on the server or demand a lot of bandwidth.

In addition, the developer version of ColdFusion can be used as a versatile personal automation tool for tasks. Consider a few examples:

  • For repetitive find-and-replace operations, ColdFusion offers powerful find-and-replace functions that use regular expressions.

    Note

    Regular expressions use special placeholder characters such as * and ? to represent unknown characters. Windows Explorer supports regular expressions that use * and ? in searching for filenames.

  • If you regularly gather the same information from the same web page, or from a number of web pages, you may find that ColdFusion’s screen scraping capabilities can automate the whole process. This enables you to gather content easily from other websites that you can use for analysis or (if authorized by the other site owner) for inclusion in your site.

  • To automate emailing with ColdFusion, you can use a database to store and retrieve names, email addresses, and perhaps other information to personalize the messages.

After ColdFusion is installed, there are a few things you need to do before you can start working with it:

  • Take some time to familiarize yourself with the functionality of the ColdFusion Administrator. This tool enables you to configure the various ColdFusion settings and even establish data sources that allow your applications to communicate with databases.

  • Configure a web server to work with ColdFusion. There is a built-in web server that requires no configuration, but it limited to development and doesn’t function as a full production web server.

  • Create or obtain a database file, created by a program such as Microsoft Access, Microsoft SQL Server, or MySQL. (On the CD accompanying this book, there is a Microsoft Access database, retroscycles.mdb, that you can use for testing.) Typically, you install the database on the ColdFusion server or the development machine on which you are working.

  • Create a System DSN (Data Source Name) so that Windows applications can access the database. You can create the System DSN with the ColdFusion Administrator.

  • If you are not developing on the same machine as that on which ColdFusion is running, you may also need an RDS (Remote Development Services) password to log on to the ColdFusion server.

  • A final, optional step is to configure debugging options by using the ColdFusion Administrator so that you get adequate information when an error occurs to help you in identifying and resolving the issue.

What’s New in ColdFusion MX 7

Several new features have been introduced in ColdFusion MX 7, including the following:

  • A brand new, Java-based engine and compiler—. This new feature allows all code to be precompiled, which means that pages load faster and more consistently.

  • Enhanced reporting tools—. Coldfusion MX 7 introduces the new CFR (ColdFusion Report) file format that allows you to create professional-looking reports and embed them in your web pages.

  • Printer-friendly web content—. Gone are the days of having to create secondary pages that enable you to display your pages in a printable format. Now ColdFusion does it all for you in either the Adobe PDF or Macromedia FlashPaper format.

  • Enhanced input forms—. ColdFusion now fully supports Flash-based forms and enables you to easily perform both client-side and server-side form validation to ensure that your visitors are completing forms properly.

  • Improved charting and graphic features—. Using the charts and graph features within ColdFusion, you can now draw data from a database and display the results in a graphical format. As your data updates, so do your charts.

  • Verity text searching—. A new, more powerful version of the Verity search engine is included in ColdFusion MX 7 and allows for more accurate text searching within documents.

  • Mobile device communication integration using Event Gateways—. ColdFusion now enables your web applications to communicate beyond the browser to devices that use the Simple Message Service (SMS) or Instant Messenger protocols. This means that when certain events occur on your site (for example, you receive a new order), you can be notified via your wireless phone or Instant Messenger application.

Understanding the ColdFusion Architecture

ColdFusion has three basic components: the server, the administrator interface, and ColdFusion Markup Language (CFML). The server is the central element because without the capability to serve pages, the other two elements are useless.

The ColdFusion server runs side by side with a web server. As the web server displays pages, the ColdFusion server watches for ColdFusion pages (pages with the .cfm extension). ColdFusion pages contain a mixture of standard HTML and CFML. If the web server receives a request for a page with a .cfm extension, it hands that request off to the ColdFusion server. The ColdFusion server then retrieves the appropriate page, processes it (a process known as preprocessing), retrieves any data that it requests from a database, and then turns all the resulting data into pure HTML. It then hands that HTML back to the web server and the web server sends the data to the client for display in the client’s browser (see Figure 17.1.).

The ColdFusion server preprocesses any CFM pages and then sends the resulting HTML back to the web server.

Figure 17.1. The ColdFusion server preprocesses any CFM pages and then sends the resulting HTML back to the web server.

During the preprocessing task, the ColdFusion server can do several things beyond just processing HTML, including

  • Database operations, such as retrieving, inserting, updating, and deleting data in databases stored on the server.

  • File operations, such as reading, writing, and appending to text files.

  • Server-to-server communications, in which the ColdFusion server exchanges data with other servers, including other ColdFusion servers, servers running Flash Remoting software, and directory servers that use Lightweight Directory Access Protocol (LDAP).

  • Page processing such as text formatting, search and replace, and building tables, forms, and charts.

  • Messaging with protocols such as SMS and Instant Messaging.

Configuring ColdFusion

Macromedia has made it relatively easy to configure and administer ColdFusion. Before you can begin coding pages and viewing them in your browser, though, you need to configure your local web server to handle ColdFusion requests and configure a data source that draws data from your database.

Using the Built-in Web Server

When you first set up ColdFusion on your local workstation, you may have configured the web server on your machine to handle ColdFusion requests. If you didn’t, or don’t know whether you did, you can take a few minutes to ensure that your machine is configured properly for serving web pages.

ColdFusion MX 7 comes with a built-in web server, but its use is limited to development purposes because it can be accessed only via the IP address 127.0.0.1, or if you use the server name localhost. In addition, the only port that the built-in server can use is port 8500.

Therefore, if you wanted to access the ColdFusion Administrator, you would have to use one of the following addresses:

http://127.0.0.1:8500/CFIDE/administrator/index.cfm

http://localhost:8500/CFIDE/administrator/index.cfm

Because of these limitations, the built-in web server isn’t very effective in a real-world environment. Therefore, if you are going to be working with ColdFusion beyond your workstation, you need a more powerful server than the server included with ColdFusion. Luckily, ColdFusion can be easily configured to work with other popular web servers such as Microsoft’s Internet Information Server (IIS) or Apache’s HTTP Server.

Configuring ColdFusion for Use with an Alternative Web Server

Configuring ColdFusion for use with Apache or IIS is an easy process. The basic steps for configuring ColdFusion to work with IIS or Apache Server are

  1. Open the Web Server Configuration Tool by choosing Start, Programs, Macromedia, ColdFusion MX 7, Web Server Configuration Tool.

    Tip

    If you already have the web server application installed, you can also open the ColdFusion administrator by typing either of the following addresses in your browser:

    http://127.0.0.1:8500/CFIDE/administrator/index.cfm

    http://localhost:8500/CFIDE/administrator/index.cfm

    Note that the reference to port 8500 is required in the URL.

  2. Add a new configuration and select the hostname and server.

  3. Choose either IIS or Apache.

  4. Choose to configure the server for ColdFusion MX applications and click OK.

Tip

For complete instructions on configuring other web server applications for use with ColdFusion, check out the document at the following address:

http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000049.htm

Configuring Data Sources

After you have ColdFusion working with a web server, the next step is to create a conduit that enables you to draw information from a database and display it on your web pages. A data source is essentially a translator that extracts data from the appropriate database and then feeds the data back to the ColdFusion server. Because each database speaks a different “language,” it’s important to use the correct conduit for your database.

Creating a data source is actually an easy process. The basic steps for creating one are as follows:

  1. Open the ColdFusion Administrator by choosing Start, Programs, ColdFusion Administrator, or by typing http://localhost/CFIDE/administrator in your web browser.

  2. Under Data & Services, click Data Sources (see Figure 17.2).

    The ColdFusion Administrator’s browser-based interface.

    Figure 17.2. The ColdFusion Administrator’s browser-based interface.

  3. In the Data Source Name dialog (see Figure 17.3), provide a name for the System DSN, choose a database driver type from the drop-down menu, and click the Add button.

    The Add New Data Source dialog.

    Figure 17.3. The Add New Data Source dialog.

    Caution

    Do not use spaces or special characters in your DSN names. If you do, you receive an error when you submit the form.

  4. In the Data Source dialog box, provide the full path to the database file on the ColdFusion server hard disk, or browse to the database file. Figure 17.4 refers to a folder path based on the IIS folder structure. The Database file field displays the path to the database file (only partially visible in the box), which is C:InetPubwwwroot etroscycles cdb9984048 etros_cycles_99300d2.mdb.

    Type the data source name and the path to your database file.

    Figure 17.4. Type the data source name and the path to your database file.

    Note

    If you are using a web server other that IIS, the path to your database may be different. Most web server applications use a root folder of wwwroot to indicate the location where web pages should be placed to be accessed by the public. Be sure that you enter the correct path to your database file when creating your data source.

    Caution

    Be careful not to name the location and database something that someone could guess. The last thing you want is some clever person downloading your database file—especially if you store user information (for example, usernames and passwords) or order information such as credit card numbers.

  5. Click Submit. The ColdFusion Administrator verifies that the data source was created successfully. When the connection is verified, OK appears in the status column for the connection.

In the Administrator, you can use the three Action buttons in this column to edit, verify, or delete the DSN. These actions do not affect the database file itself, but only the DSN.

After you have your web server configured to handle ColdFusion requests and a connection to your database, you’re almost ready to open Dreamweaver and begin developing web pages that can display dynamic data. If, however, you are going to use Flash to display dynamic data, there a few other things to consider.

Using Flash to Access the ColdFusion Server

Flash can be used to implement the client side of ColdFusion applications. A Flash client typically interacts with a ColdFusion server in one of two ways: using web services or using Flash Remoting. Figure 17.5 shows the architecture and protocols associated with each approach.

The Flash Player (lower left) can access the ColdFusion server with either the WebServiceConnector component or Flash Remoting.

Figure 17.5. The Flash Player (lower left) can access the ColdFusion server with either the WebServiceConnector component or Flash Remoting.

Web Services

The web services architecture enables the client to get dynamic data from servers by making requests with Simple Object Access Protocol (SOAP) and by receiving XML replies. By using standard, open protocols, web services enable any-to-any communication. For example, you can create web services that run on the ColdFusion server, and they can be accessed by clients using PHP, JSP, ASP.NET, or any other technology that supports web services standards.

Note, however, that the Flash Player’s prohibition on cross-domain data transfers without a cross-domain policy file puts a serious restriction on this potential for universal communication.

Web services are best accessed from the Flash Player through the WebServiceConnector component in Flash MX 2004 Professional. The WebServiceConnector makes it easy to get the basic web services connection going.

The web services architecture requires the client to communicate with the server via a proxy, which replicates server behaviors on a local server, such as the ColdFusion server.

Dreamweaver has tools for creating ColdFusion server behaviors for use as web services. Dreamweaver also makes it easy to create the proxy for the client on the ColdFusion server. Finally, Dreamweaver makes it easy to create simple client interactions with web services.

Flash Remoting

To use Flash Remoting, you have to download the Flash Remoting components from www.macromedia.com. With the components installed, your Flash applications can communicate directly with the ColdFusion server and interact with a database.

Flash Remoting clients communicate via the Flash Remoting Gateway, a standard feature of the ColdFusion server. The Flash Remoting client invokes a function, created by the ColdFusion developer and often contained in a ColdFusion component (CFC) on the ColdFusion server. The function returns a value to the Flash Remoting client.

Flash Remoting is the most efficient way to communicate with the ColdFusion server. The ColdFusion server and the Flash client store data in the same format, eliminating the need for time-consuming translation required with technologies like XML. In addition, the proprietary Action Message Format (AFM) used for communication between client and server is efficient and compact.

Troubleshooting

I’m getting a Connection verification failed error. What’s going on?

If you get a message such as Connection verification failed for data source: retroscycles, look at what comes after it. A lot of it may not be very helpful, but somewhere in there, there should be a solid clue as to what is wrong. For instance, Could not find file tells you there is something wrong with the filename or path that you entered in the Database box.

If the file is on your local machine, and the error message says Please check your username, password, URL, and other connectivity info, the database file may be protected by a username and password. Two options are to uncheck Use Default Username and provide the correct username and password in the appropriate boxes (ColdFusion Username and ColdFusion Password), or to un-protect the database by using the database management system.

If all else fails, you might try using the Windows interface for working with DSNs (Start, Settings, Control Panel, Administrative Tools, Data Sources [ODBC], System DSN tab) to create the System DSN.

Best Practices—When Is ColdFusion the Right Platform?

One of the few drawbacks of ColdFusion over other platforms such as ASP, ASP.NET, JSP, and PHP is that ColdFusion is relatively expensive compared to the others. ASP functionality is native to IIS, so no additional downloads or configuration is required. JSP, PHP, and ASP.NET are free downloads that can be downloaded and installed easily. ColdFusion, on the other hand, can cost up to $6,000 for the Enterprise Edition. So why use a product that costs that much, when you can get others for free? There are several reasons.

First, the $6,000 Enterprise Edition is really for companies that are going to run multiple sites and applications from more than one server. So if your company is looking to develop a web presence, an intranet, and a host of dynamic applications, it would make sense to spend the money on a server platform that will not only enable you to leverage database content, but has search functionality, reporting capabilities, and a wide variety of messaging functionality built in. That way, you’re not having to look around at third-party applications that might affect the way your applications perform.

The Standard Edition, weighing in at $1,300, is also oriented toward an environment where multiple applications and sites will be developed, but everything will be stored on a single server. This is an ideal option for small- to medium-sized businesses who need their own web servers (as opposed to a hosted site).

But what if your company or organization doesn’t have the budget for $1,300 plus the cost of a server and someone to maintain it? The answer is to find a hosting company that offers access to the ColdFusion platform to its clients. There are quite a few reasonably priced companies out there that offer ColdFusion in their packages, and because ColdFusion has a web-based configuration utility, they often allow you to create DSN entries on the fly via your browser.

So if you aren’t part of a Fortune 500 company or don’t have a budget that allows you to purchase the necessary equipment and licenses to run ColdFusion...fear not! Options are available that will allow you to leverage all that ColdFusion has to offer without breaking the bank.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.51.157