DDYYNNAAMMIICC EE--CCOOMMMMEERRCCEE AAPPPPSS U.S. $8.99 (Canada $9.99) ColdFusionJournal.com January/February,1999 Volume:1 Issue:1 FFRREEEE aacccceessss ttoo DDiiggiittaall EEddiittiioonn pp..3344 From the Editor Welcome to CFDJ! Chad Sitler page5 Programming Techniques Dynamic Variable Length Forms by Geoff Caras page38 Tips & Techniques File Upload Utility with ColdFusion Leveraging CF: Putting Client/Server on the Web 10 by Matt Newberry page40 Replicating the User Interface and Functionality Jerry Bradenbaugh Product Review AbleCommerce CFDJ Feature: What’s Different About ColdFusion’s 4.0 Developer 2.6 18 Some of the Enhancements That Make by Tom Taulli page42 the Upgrade Worthwhile for Developers Richard Schulze Custom Tags: Building The Data Path: From Database to Web Page and Back Custom Tags 22 Using ColdFusion Using SQL,HTML and JavaScript to Retrieve Data Andy Birchall by Ashley King page47 A Look Inside: Creating a ‘Live’ColdFusion Site CF News page36 26 User Groups page50 Requesting Information from the Server Raymond Camden RETAILERS PLEASE DISPLAY UNTIL MARCH 31, 1999 ColdFusion & CGI: Transitioning to ColdFusion 30 ColdFusion and the Web Go Hand in Hand Jim Esten ColdFusion Slick Tricks: Taming the Cookie Monster SYS-CON 44 PUBLICATIONS Hysteria About Cookies is Wildly Distorted Bob Siegel Able Solutions www.ablecommerce.com 2 COLDFUSION DEVELOPER(cid:213)S JOURNAL • VOLUME:1 ISSUE:1 www.ColdFusionJournal.com Allaire 1 www.allaire.com www.ColdFusionJournal.com VOLUME:1 ISSUE:1 • COLDFUSION DEVELOPER(cid:213)S JOURNAL 3 Catouzer www.catouzer.com 4 COLDFUSION DEVELOPER(cid:213)S JOURNAL • VOLUME:1 ISSUE:1 www.ColdFusionJournal.com FROM THE EDITOR Welcome to CFDJ! EDITORIAL ADVISORY BOARD Geoff Caras, Jim Esten, Ben Forta, Steve Nelson, Richard Schulze Editor in Chief: Chad Sitler Art Director: Jim Morgan If you’ve picked up the premier issue every movement of the package before it Executive Editor: Scott Davison Managing Editor: Hollis K. Osher of ColdFusion Developer’s Journal arrives on our front porch? The trick now Senior Editor: M’lou Pinkham expecting to read about a way to create is to utilize these trends to our advan- Production Editor: Brian Christensen Product Review Editor: Tom Taulli an infinite energy source, there’s no need tage. That’s what ColdFusion can do for Tips & Techniques Editor: Matt Newberry to read further. However, if you’ve picked you. WRITERS IN THIS ISSUE up this issue expecting to read about an When I was younger – and even now! – Andy Birchall, Jerry Bradenbaugh, energy source that can take raw data and my father always said the same thing Raymond Camden, Geoff Caras, Jim Esten, turn it into something useful and even when I tried to tell him about something Ben Forta, Ashley King, Matt Newberry, Richard Schulze, Bob Siegel, Tom Taulli pleasing to the eye, then read on. great I was doing or about to do: “Don’t SUBSCRIPTIONS In 1995 the Allaire Corporation was tell me, show me!” [email protected] founded and began its foray into the rela- Well, CFDJ plans to one-up that com- For subscriptions and requests for bulk orders, tively uncharted territory of electronic ment. We’re not just going to tell you that please send your letters to Subscription Department. commerce and business information sys- CFDJ is something great. We’re not just Subscription Hotline: 800 513-7111 tems. The evolution of the Web forced going to show you, either. We’re going to Cover Price: $8.99/issue developers to create dynamic, interactive do both. As in our other journals, Java Domestic: $49.99/yr. (6 issues) Canada/Mexico: $69.99/yr. Web sites, but the relative infancy of Developer’s Journaland PowerBuilder Overseas: $99.99/yr HTML restricted their ability to do this. A Developer’s Journal, many articles will Back Issues: $12 each better tool was needed. ColdFusion was be followed by the actual codes used by Publisher, President and CEO: Fuat A.Kircaali the result. Now ColdFusion Developer’s the author. But we’re not stopping there. Vice President, Production: Jim Morgan Vice President, Marketing: Carmen Gonzalez Journal breaks onto the scene. If you check out www.ColdFusionJour- Advertising Manager: Robin Forma CFDJ has amassed articles from the nal.com, you, as a subscriber to CFDJ, Advertising Assistant: Jaclyn Redmond Accounting: Ignacio Arellano front-runners in the ColdFusion develop- can read choice articles and even down- Graphic Designers: Robin Groves ment field, including Ben Forta, the well- load the source codes mentioned in the Alex Botero known CF evangelist and author of The articles. Dad would be proud. WebMaster: Robert Diamond Customer Service: Sian O’Gorman ColdFusion Web Database Construction When SYS-CON was founded in 1994, Paula Horowitz Kit. our mission was simple: publish the best Online Customer Service: Mitchell Low These articles aren’t geared solely to technical journals and distribute the EDITORIAL OFFICES experienced CF developers, but to the most compelling, informative and timely SYS-CON Publications, Inc. beginner as well. It’s CFDJ’s goal to make information available anywhere. As we 39 E. Central Ave., Pearl River, NY 10965 Telephone: 914 735-1900 Fax: 914 735-3922 sure that no issue is beyond the ability of approach our sixth year of publishing [email protected] beginners, or too simplistic for those quality technical journals, we have the COLDFUSION DEVELOPER’S JOURNAL who’ve been playing with CF tags for satisfaction of knowing that we’re contin- is published bimonthly (6 times a year) years. uing to fulfill this mission. for $49.99 by SYS-CON Publications, Inc., 39 E. Central Ave., Pearl River, NY 10965-2306. The most recent development in the Today SYS-CON Publications, Inc., is Application to mail at Periodicals Postage rates is pending world of CF is ColdFusion 4.0. Newly one of America’s fastest-growing compa- at Pearl River, NY 10965 and additional mailing offices. enhanced properties of previous CF ver- nies, and we’re excited by the opportuni- POSTMASTER: Send address changes to: COLDFUSION DEVELOPER’S JOURNAL, sions – as well as new tags and the ability ties that ColdFusion Developer’s Jour- SYS-CON Publications, Inc., to create more powerful custom tags – nal offers CF and Web developers as a 39 E. Central Ave., Pearl River, NY 10965-2306. highlight this newest release from Allaire. resource that will propel CF development © COPYRIGHT The ability to integrate other program- and use to even greater heights. Copyright ©1999 by SYS-CON Publications,Inc. All rights reserved. No part of this publication may be reproduced or transmitted in any form ming languages also makes ColdFusion We want to make this journal one of or by any means,electronic or mechanical,including photocopy or any the database integration tool of both the the most indispensable sources of quali- information storage and retrieval system,without written permission. For promotional reprints,contact reprint coordinator. present and the future. ty CF information in the world. So here it SYS-CON Publications,Inc.,reserves the right to revise,republish and Without a doubt, the e-commerce is. You hold in your hand a collector’s authorize its readers to use the articles submitted for publication. industry is becoming one of the most item. We also want to hear your ques- ISSN # 1087-6944 explosive aspects of the Web. Who’d tions and comments, so please contact WORLDWIDE DISTRIBUTIONby Curtis Circulation Company have thought, as they bought their state- me or any of the editorial staff. It’s only 739 River Road,New Milford NJ 07646-3048 Phone:201 634-7400 of-the-art 2400-baud modem, that they’d through your input that we can create a DISTRIBUTED in USA by one day be buying, selling and trading magazine that’s useful, informative and International Periodical Distributors stock over the Internet? Did they ever enjoyable. 674 Via De La Valle,Suite 204,Solana Beach,CA 92075 619 481-5928 think they’d be able to choose from mil- All brand and product names used on these pages are trade names, service marks or tradmarks oftheir respective companies. lions of book and compact disc titles and About the Author SYS-CON buy them without ever leaving the com- Chad Sitler is editor in chief of ColdFusion Developer’s PUBLICATIONS fort of their homes? And (in relation to Journal.Chad can be reached at [email protected]. ColdFusion) how on earth could we make these purchases and be able to track [email protected] www.ColdFusionJournal.com VOLUME:1 ISSUE:1 • COLDFUSION DEVELOPER(cid:213)S JOURNAL 5 <BF>ON <CF> OObbjjeecc TThhee byBen Forta (cid:231) There are lots of ColdFusion developers out there – that’s good for us. Instantiating COM Objects To use an installed COM object, the first (cid:231) There are also lots of ASP developers out there – that’s good for them. thing you have to do is initialize it for use. Usually this involves instantiating the (cid:231) ColdFusion developers are empowered with multiple ways to extend the object. ColdFusion language – that’s good for us. To initialize COM objects in Cold Fusion, you use the <CFOBJECT> tag, which takes (cid:231) ASP developers are not as lucky – that’s bad for them. the name of the object as an attribute and a name that you use to refer to that object (cid:231) ASP developers rely on COM objects to extend ASP – that’s good for us. once it’s been initialized. The code to ini- tialize AspChart looks like this: That’s good for us? Yes, most definitely. ServerObjects is Stephen Genusa, one of <CFOBJECT ACTION=“CREATE” NAME=“Chart” ASP has no built-in functionality for many the leading authorities on ASP develop- CLASS=“ASPChart.Chart”> simple things that are built into ColdFusion, ment. so ASP developers use COM objects exten- In this example the <CFOBJECT> tag is sively, even for those little things that we Understanding COM Objects creating an instance of the chart object. CFers take for granted: generating SMTP e- COM, the acronym for Component The object’s name is “ASPChart.Chart” mail messages, for example. To generate e- Object Model, is a software specification (every object has a unique name) and it is mail, ASP developers must install third- designed to allow applications to dynami- passed in the CLASS attribute. <CFOBJECT> party components that provide them with cally link components at runtime. This instantiates the object, which can now be that functionality. means that developers can encapsulate referred to as “Chart” as specified in the So why is this good news for us? Well, functionality into clean, published compo- NAME attribute. Just as a point of refer- the good news is that there are hundreds of nents and then allow other applications to ence, here’s the ASP code that does the third-party components out there, offering interact with them. In other words, COM same thing: all sorts of functionality. Some are freebies. objects are a way to create black-boxed Others are shareware or commercial soft- reusable components that other develop- Set ware. And ColdFusion developers can take ers can take advantage of. Chart=Server.CreateObject(“ASPChart.Chart”) advantage of them all. COM objects are usually DLL or EXE files This column won’t teach you how to and can be written in almost any language As you can see, converting the sample write your own COM objects. It will, howev- imaginable, such as C/C++, Visual Basic, ASP instantiation code to ColdFusion code er, teach you how to use COM objects and Java and Delphi. Once the object is written, is pretty simple. how to convert the sample ASP code that it’s installed and registered on the comput- accompanies most COM objects into CF er it will be used on. Registering the COM Setting Object Properties code. Note that the examples here use an object publishes it (and its interfaces) to Now that the object is instantiated, we excellent graphing object, AspChart, that other applications so they can use it. need to pass values to it. COM object val- allows you to create professional and flexi- Almost all COM objects come with ues are called properties, and every COM ble charts on the fly in several file formats. installation and registration instructions. object has a different set of properties. AspChart is created by ServerObjects Inc. Those instructions are the same regardless Refer to the object documentation for a list (www.serverobjects.com). The president of of the application using the COM object. of properties and their values. 6 COLDFUSION DEVELOPER(cid:213)S JOURNAL • VOLUME:1 ISSUE:1 www.ColdFusionJournal.com cctt AAllll ooff Iitt Two of AspChart’s properties are Height <CFSET ChartFont.Name=“Times New Roman”> Some methods take one or more parame- and Width. These specify the size (in pix- ters. To pass parameters to a method in Cold- els) of the image to be generated. The ASP ChartFont is a temporary variable that Fusion, just specify them in a comma-delim- code to set these properties is: points to the Chart.ChartTitleFont proper- ited list between the “(”and“)” characters. ty. ChartFont.Size thus points to the Size That’s all there is to it. Pretty simple indeed. Chart.Height=300 subproperty within the ChartTitleFont Chart.Width=500 property. Once again, as you can see, with a Where to Go from Here little effort, converting ASP subproperty- Now that you know how easily ColdFu- ColdFusion programmers set object setting code to ColdFusion code is pretty sion developers can take advantage of COM properties with the familiar CFSET tag. To easy to do. objects and COM technology, here are set the same two properties with the same some useful sites for you to visit: two values, your code would look like this: Invoking Object Methods • The Microsoft COM Technologies home The last thing you need to know is how page is at www.microsoft.com/com. This <CFSET Chart.Height=300> to invoke object methods. A method is a is a great place to learn more about COM <CFSET Chart.Width=500> function within a COM object. Whereas and there are also plenty of links to COM properties set values within an object, objects and vendors. As you can see, converting ASP proper- methods actually execute the function • ServerObjects Inc. have created a whole ty-setting code to ColdFusion code is also using any properties already set. (For this set of COM objects (AspChart is one of pretty simple. reason, methods are almost always invoked many). Their home page is at www.- after all the properties have been set.) serverobjects.com. Setting Object Subproperties Every COM object has at least one • The CNET ActiveX page at www.- Some properties contain subproperties. method, and some have many more. The activex.com has lists of hundreds of For example, AspChart lets you specify the code to invoke an object method in ASP COM objects, with reviews and recom- font information to use for the chart title. looks like this: mendations as well. The ASP code to set the size and font name would be: Chart.SaveChart For more information about ColdFusion’s COM support, the <CFOBJECT> tag and writing Chart.ChartTitleFont.Size=20 This invokes the AspChart SaveChart COM objects, see the chapter entitled “Interfac- Chart.ChartTitleFont.Name=“Times New Roman” method that actually creates the image file ing with COM and DCOM Objects” in my book based on all the properties already set. The ColdFusion Web Application Construction Kit ColdFusion doesn’t let you set subprop- equivalent ColdFusion code is: (ISBN 07897-14140). erties directly. Instead, you have to first define a variable that points to the proper- <CFSET temp=Chart.SaveChart()> About the Author ty, then set the subproperties within that Ben Forta is Allaire Corporation’s product evangelist for new variable. To demonstrate this tech- From ColdFusion’s perspective, the only the ColdFusion product line.He is the author of the nique, the following code sets the same two difference between setting a property and best-selling ColdFusion Web Application Construction subproperties as the ASP code above: invoking a method is that methods must Kitand the new Advanced ColdFusion 4 Development have () characters after the method name (both published by Que). <CFSET ChartFont=Chart.ChartTitleFont> (methods are essentially functions, and [email protected] <CFSET ChartFont.Size=20> ColdFusion uses () to distinguish functions). www.ColdFusionJournal.com VOLUME:1 ISSUE:1 • COLDFUSION DEVELOPER(cid:213)S JOURNAL 7 IMHO The Future (and Past) of E-commerce Great oaks from little acorns grow byJeremy Allaire applications on the Web. Based on Metcalfe’s Law, important to Web developers forced to work in which states that the value of a network increases mixed Web application environments. With Sometimes simple tech- exponentially with every node added to the net- WDDX you can reuse code and data, preserving nologies combine in ways work, these companies are building Web syndi- your technology investment and supporting that create massive innova- cate networks where applications serve both end richer development and deployment models. tion and opportunity. The users AND other Web applications. This is important to customers who are con- Web itself is a modern exam- A good example can be drawn from e-com- cerned that an investment in a given platform is ple. Formed as a simple merce. Any merchant setting up a commerce site closed and can’t be used in the future. WDDX request/response docu- will have back-end shipping and fulfillment provides a conduit to your Web applications that ment-delivery mechanism, the core technologies requirements. This often involves a Web applica- can be reused by other applications. of the Web -- HTML and HTTP -- were central to a tion invoking and tracking a shipment via a One limitation of the basic Web architecture broad computing platform shift. It’s because provider like FedEx. In the world of Web syndi- is that with an HTML-based user interface you’re these technologies were so simple and accessi- cation, FedEx.com is less an end-user site and limited in the richness of interactivity that can ble that the Web exploded the way it did. more an automated portal into the FedEx busi- be provided to an end user in the browser itself In 1994 we saw that this simple technology ness computing infrastructure. And the data and -- HTML is a static user interface. One secondary could be extended with two other well-known, services performed with FedEx can be done in effect of this is that simple forms of interactivity simple technologies -- scripting and databases. an automated fashion using any Web application require additional requests to the server, With CFML and a basic database engine, the Web server or programming language, over HTTP and increasing server load and decreasing the appli- could be used both as a publishing medium and using WDDX. cation’s performance. as the foundation for interactive online business. In another example, the owners of a Web site In the past few years the capabilities of the Like the Web itself, technology platforms such as offering recipes for Italian food lovers might browser increased through the use of JavaScript CF have evolved to meet the new demands of want to offer additional content and commerce and DHTML. The 4.0-level browsers have rich online businesses. CF 4.0 represents a mammoth features. Additional content could include popu- programming models that can be used to create release for Allaire, with major innovations in lar books on Italian cooking from Amazon.com flexible and interactive user interfaces. But these rapid development, scalable deployment, open (including all of the books’ details and user have been underleveraged because of browser integration and total security. reviews) and even a custom user interface for incompatibilities, and it’s been difficult -- if not But hidden inside CF 4.0 is another “simplici- purchasing. All this could be handled under the impossible -- to move application data between ty revolution.” Evolving from the basic need to hood (with the recipe site using ASP, and Ama- Web browsers and application servers. So exchange query data between CF servers, the zon.com using CGI and a custom C++ applica- despite an increase in the capabilities of Web Web Distributed Data Exchange (WDDX) tion) with the recipe site providing a custom clients, even simple data binding has been emerged as a simple technology that solves content and commerce experience that’s molded impossible. enormously complex problems. into the user experience. WDDX provides a simple, lightweight cross- WDDX is an XML-based technology that Web syndicate networks open new business browser solution to increasing usability and per- enables the exchange of complex data between models based on the networked economy. With- formance in your Web applications. Because programming languages, creating “Web syndi- out a doubt it’s the most exciting application of JavaScript supports WDDX, you can easily move cate networks”. WDDX consists of a language- WDDX. data between any server-based applications and independent representation of data and a set of Huge challenges continue to face Web appli- browser-based applications using JavaScript. In modules for a wide variety of languages that use cation builders. By their nature, Web applica- this model you could have a database query on WDDX. (For more technical details or to down- tions often involve tying together data from mul- the server passed to a JavaScript browser where load the WDDX SDK, check out www.wddx.org.) titudes of disparate systems. They involve inte- it works with the data locally, rendering it using WDDX and the different WDDX language plat- grating with legacy code and applications, even the Document Object Model and DHTML, then form modules are all open-source, freeware tech- coexisting with desktop fat-client applications passing any changed data back to the server nologies and don’t require CF. based on Visual Basic, MS Access or even Java. when it’s completed. The WDDX SDK includes WDDX improves what you can do with the WDDX eases this by providing an open, cross- extensive examples for using WDDX to enhance Web in three major ways: (1) it can be used as platform and cross-language model for sharing DHTML user interfaces and to create data-bind- the foundation for building Web syndicate net- data. ing and offline browser applications. works, where the content and commerce assets Because WDDX is XML-based, moving com- I strongly encourage you to check out WDDX of Web sites are exposed and shared to other plex data between systems can be handled using via the project homepage (www.wddx.org), and sites on the network; (2) it increases platform simple text strings. And since WDDX is available let us know what you think. interoperability and legacy migration; and (3) it for use with Java and COM, your application data increases the performance and usability of Web can reach systems built with almost any com- About the Author applications. mon desktop programming tool or OS platform. Jeremy Allaire is a cofounder and vice president of WDDX can radically change your Web-busi- Often referred to as XML Middleware, this use of technology strategy at Allaire.He helps determine the ness model. Until now, most companies and site XML allows you to “tunnel” data between sys- company’s future product direction and is responsible for developers have seen their investments in Web tems, despite differences in implementation and establishing key strategic partnerships within the Internet systems and Web sites primarily aimed at end runtime environments. WDDX shields you from industry.Jeremy has been a regular author and analyst on users who access applications through Web having to know anything about XML itself – all Internet technologies for the past seven years,and he browsers. Recently, however, all kinds of compa- transformations and data exchanges happen holds degrees in both political science and philosophy from nies have begun to realize that their application under the hood, using things like XML and HTTP Macalester College. assets could be leveraged in more substantial as transports for application data. [email protected] ways by exposing them as “services” to other The platform interoperability advantages are 8 COLDFUSION DEVELOPER(cid:213)S JOURNAL • VOLUME:1 ISSUE:1 www.ColdFusionJournal.com Eprise www.eprise.com www.ColdFusionJournal.com VOLUME:1 ISSUE:1 • COLDFUSION DEVELOPER(cid:213)S JOURNAL 9 CFDJ SERIES FEATURE LEVERAGING COLDFUSION: Putting Client/Server on the Web PART 1 Replicating Replicating the User Interface the User Interface and Functionality and Functionality by Jerry Bradenbaugh This article is the first in a series of three did so by examining a portion of the appli- The FRS Overview focused on using ColdFusion to replicate cation Red Oak developed called the Fulfill- Business Challenge client/server application functionality across an ment Request System. You’ll see screen The Web-enabled application must allow intranet,extranet or the Web.It discusses repli- shots of the interface and much of the code users to process customer orders (taken by cating the look and “feel” of a client/server behind it. phone or e-mail) via their intranet. Since the application from a user interface perspective. As you read on, remember that ColdFu- representatives take the broker orders in a sion is designed to easily accommodate fast-paced environment, the application One of our clients came to us with other technologies, so we’ll be covering must have a clean (graphic-free), fast inter- a problem. The client had a frumpy but HTML, JavaScript, ODBC and SQL state- face. The application must also look similar effective fulfillment request application ments. If you’re not up to par on these tech- to (if not better than) the client/server ver- written in MSAccess. They wanted to con- nologies, keep an online reference close by. sion that representatives use to easily mod- vert it to an intranet application to ify or add customer information and send (1) increase user access and scalability, The links in Table 1 should help: orders to the shipping department. (2) improve performance time and (3) maintain the same look on the intranet as Technology Site Name URL it had as a client/server application. Enter ColdFusion. HTML World Wide Web Consortium http://www.w3.org/ In the next few pages we’ll take a closer ZDNet:HTML User Garage http://www.zdnet.com/products/htmluser/garage.html look at how you can use ColdFusion to meet JavaScript Netscape’s DevEdge http://developer.netscape.com your client’s business requirements across HotSyte:The JavaScript Resource http://www.serve.com/hotsyte/ an intranet, extranet or the Web by con- SQL Introduction to Structured Query Language http://w3.one.net/~jhoffman/sqltut.htm verting a client/server application to a Web- ODBC Microsoft Data Access Components http://www.microsoft.com/data/reference/odbc2.htm enabled application. I’ll show you how the Red Oak Technologies development team Table 1 10 COLDFUSION DEVELOPER(cid:213)S JOURNAL • VOLUME:1 ISSUE:1 www.ColdFusionJournal.com