Introducing ColdFusion MX

Welcome to ColdFusion MX! ColdFusion is one of the easiest-touse programming languages, yet it can build the most powerful, extensible Web applications in the world. ColdFusion’s elegant simplicity is appreciated by both novice programmers who want a fast start on building real-world applications and experienced developers coming from complicated Web technologies such as Active Server Pages. You may be wondering how much effort learning ColdFusion takes. This really is up to you, because the more time that you spend with ColdFusion, the better you become with it. If you already know a little HTML and you just want to build a simple Web site that presents your collection of antique whistles to the world, you can probably be online with your first application in anywhere from three days to a week. A few more weeks of diligent practice are likely to see you selling your whistles over the Internet, and in a year, who knows . ? You may start building WorldWhistleExchange.com! You need to know surprisingly little before diving into ColdFusion, but the more experience that you have with other programming languages, the better. If you know a little HTML and you understand how the Internet works, you’re good to get started. If you’ve heavily programmed in a language such as C++ or Java, you’re home free, because you’re already familiar with solid programming concepts. If you’re just beginning your first foray into the world of programming and the Internet, be aware that you need to spend plenty of time going over the basics that we present in Part I of this book. You should also get involved in your local ColdFusion user group, which is sure to be an excellent resource for learning new techniques. The bottom line is that anyone can learn ColdFusion—it’s just a matter of trying.

pdf125 trang | Chia sẻ: tlsuongmuoi | Lượt xem: 2096 | Lượt tải: 0download
Bạn đang xem trước 20 trang tài liệu Introducing ColdFusion MX, để xem tài liệu hoàn chỉnh bạn click vào nút DOWNLOAD ở trên
CHURVIS, HELMS, AREHART, & CHURVIS If ColdFusion MX can do it, you can do it too . . . As e-business continues to grab market share, you’re continually challenged to create faster, cheaper, and more reliable e-commerce Web applications. ColdFusion MX offers the quickest, most reliable way to build and deploy them, and this comprehensive reference guides you from writing your first application all the way through the complexities of integrating with Web services, Flash, Java, COM, and XML. From installation to database connection configuration, from tag and function usage to code reuse, it’s like having your personal team of experts on call. Inside, you’ll find complete coverage of ColdFusion MX • Create highly interactive, database-driven Web sites with ColdFusion’s intuitive, tag-based programming language • Build and deploy content publishing systems, online stores, business reporting applications, self-service solutions, and more • Easily create and use Web services and ColdFusion Components • Integrate applications with other technologies like Java, COM, and XML • Learn how — and why — to document your code, handle source version control, and integrate security, testing, and performance • Discover how to use ColdFusion with databases, Web services, and Flash Remoting • Extend ColdFusion applications with features like task scheduling, file operations, Verity text searching, and charting Shelving Category: Internet / Web Site Design Reader Level: Beginning to Advanced System Requirements: PC running Windows 98, Windows 2000, Windows NT4 (SP6a or later) or Windows XP. See the What’s on the CD-ROM Appendix for details and complete system requirements. ISBN 0-7645-4622-8 $49.99 USA $74.99 CANADA £37.50 UK C o l d F u s i o n M X Invigorate your Web sites with ColdFusion’s rich development language Activate the power of ColdFusion to build more robust applications Integrate CFMX with powerful technologies like Flash, JSP, XML, and COM Adam Phillip Churvis, Hal Helms, Charles Arehart, and David Churvis ,!7IA7G4-fegcci!:p;o;t;T;T Trial software and code listings on CD-ROM w w w . w i l e y . c o m / c o m p b o o k s / Logical Data Model (LDM) CategoryCode (PK)(FK) varchar(4) NOT NULL ItemNumber (PK)(FK) varchar(15) NOT NULL CategoryInventoryItem Physical Data Model (PDM) InventoryItem ItemNumber VARCHAR(15) NOT NULL ParentItemNumber VARCHAR(15) NULL Description VARCHAR(40) NOT NULL UnitPrice NUMERIC(12,2) NOT NULL Category CategoryCode VARCHAR(4) NOT NULL CategoryName VARCHAR(20) NOT NULL InventoryItem ItemNumber (PK) varchar(15) NOT NULL ParentItemNumber varchar(15) NULL Description varchar(40) NOT NULL UnitPrice numeric(12,2) NOT NULL Category CategoryCode (PK) varchar(4) NOT NULL CategoryName varchar(20) NOT NULL 100% O N E H U N D R E D P E R C E N T COMPREHENSIVE AU THO R I TAT I V E WHAT YOU NEED O N E H U N D R E D P E R C E N T Bonus CD-ROM • Trial versions of Adalon Developer Edition, CommerceBlocks, DataFactory, LoRCAT, SourceOffSite, and Macromedia ColdFusion Server MX, plus other software • Author files, code listings and samples, and real-world applications you can use • Searchable e-version of the book ColdFusion MX Bible Perfect Bind • Trim: 7 3/8 x 9 1/4 • • 4 color process • Yellow prints 110y 15m • + spot varnish (see spot varnish pdf) • Matte laminate *85555-ABJGHg 100% C O M P R E H E N S I V E ® C o l d F u s i o n M X ® ® BONUS CD-ROM AND COMPANION WEB SITE Software samples on CD-ROM plus more resources online Learn database modeling, triggers, and stored procedures Company.cfc ... Model Layer ColdFusion Components Controller Layer Flash Remoting Gateway View Layer Flash Movie 1 2 3 4 5 User chooses company, which triggers change handler funcion getCompany() function GetCompany_Result(companyRecord) { companyName_txt.text = companyRecord.items[0].CompanyName; address_txt.text = companyRecord.items[0].Address; city_txt.text = companyRecord.items[0].City; state_txt.text = companyRecord.items[0].State; zipCode_txt.text = companyRecord.items[0].ZipCode; 6 Flash movie's GetCompany_Results() ActionScript function populates movie fields from returned record, which is received as an object named companyRecord ActionScript getCompany() calls GetCompany(companyID) in gateway Gateway routes request with company ID to . . . (Company.cfc).GetCompany() Gateway routes responnse with compRec to . . . (FlashMovie).GetCompany_Result() This is one view element... ...and this is a second view element. Choose Company: ABC Company, Inc. Company Name: ABC Company, Inc. Address: 1234 Main Street City: Atlanta State: GA Zip Code: 30303 Create a complete Flash Remoting application Companion Web site at www.wiley.com/compbooks/churvis provides code samples, useful links, and more 546228 Cover 1/22/03 12:26 PM Page 1 ColdFusion® MX Bible 546228 FM.F 1/31/03 3:07 PM Page i 546228 FM.F 1/31/03 3:07 PM Page ii ColdFusion® MX Bible Adam Phillip Churvis, Hal Helms, Charles Arehart, David Churvis 546228 FM.F 1/31/03 3:07 PM Page iii LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: WHILE THE PUBLISHER AND AUTHOR HAVE USED THEIR BEST EFFORTS IN PREPARING THIS BOOK, THEY MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES OR WRITTEN SALES MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR YOUR SITUATION. YOU SHOULD CONSULT WITH A PROFESSIONAL WHERE APPROPRIATE. NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL, CONSEQUENTIAL, OR OTHER DAMAGES. ColdFusion® MX Bible Published by Wiley Publishing, Inc. 909 Third Avenue New York, NY 10022 www.wiley.com Copyright © 2003 by Wiley Publishing, Inc., Indianapolis, Indiana Library of Congress Number: 2001093600 ISBN: 0-7645-4622-8 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/SQ/QS/QT/IN Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4447, E-Mail: permcoordinator@wiley.com. For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at 800-762-2974, outside the U.S. at 317-572-3993 or fax 317-572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Trademarks: Wiley, the Wiley Publishing logo and related trade dress are trademarks or registered trademarks of Wiley Publishing, Inc., in the United States and other countries, and may not be used without written permission. ColdFusion is a trademark or registered trademark of Macromedia, Inc. in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. is a trademark of Wiley Publishing, Inc. 546228 FM.F 1/31/03 3:07 PM Page iv About the Authors Adam Churvis is a database and scalability specialist with more than 20 years of software-industry experience in many languages and database platforms. He is the founder and President of Productivity Enhancement, a full-service consulting, train- ing, and commercial-software development firm, which is entering its 18th year in business and is also the parent company of ColdFusionTraining.com, which pro- vides the most advanced and intensive ColdFusion training in the world. Adam is a member of Team Macromedia and also serves as a current board member and for- mer President of the Atlanta ColdFusion User Group, and he enjoys speaking at other CFUGs as well. He has a wife, whom he worships, three children, three cats, and lots and lots of computers. He can be reached at adam@ProductivityEnhancement.com. Hal Helms is an internationally-known speaker, writer, and trainer on Java, ColdFusion, and best practices in software development. Hal writes the popular “Occasional Newsletter” available at halhelms.com, and you can reach him at hal@techspedition.com. Charles Arehart is the founder and CTO of SysteManage, based in Laurel, Maryland. A Macromedia certified advanced developer and instructor, Charles is also a member of Team Macromedia who has logged more than 5 years with ColdFusion and more than 20 years in IT. His monthly “Journeyman” column appears in ColdFusion Developer’s Journal, where he’s a technical editor. He is a regular speaker at developer conferences, seminars, and user group meetings worldwide, and also provides training and short-term consulting. You can reach him at carehart@systemanage.com. David Churvis is a software-development specialist who got his start in object- oriented programming at the age of eight. He has worked in HyperCard, SuperCard, FutureBasic, CFML, VTML/WIZML, Transact/SQL, PL/SQL, Delphi, C, C++, C#, Java, JSP, JavaScript, VBScript, and DHTML. David is Vice President of Development for Productivity Enhancement and is the chief programmer behind the CommerceBlocks line of modular ColdFusion development tools and LoRCAT, the Load Reduction and Concentration Analysis Tool for ColdFusion. 546228 FM.F 1/31/03 3:07 PM Page v Credits Senior Acquisitions Editor Sharon Cox Project Editor Sharon Nash Technical Editor Jen and Peter deHaan Copy Editor William A. Barton Editorial Manager Mary Beth Wakefield Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Bob Ipsen Executive Editorial Director Mary Bednarek Project Coordinator Nancee Reeves Graphics and Production Specialists Melissa Auciello-Brogan, Beth Brooks, Jennifer Click, Joyce Haughey, Stephanie D. Jumper, Jeremey Unger Quality Control Technician Susan Moritz, Charles Spencer Permissions Editor Carmen Krikorian Media Development Specialist Travis Silvers Proofreading and Indexing TECHBOOKS Production Services 546228 FM.F 1/31/03 3:07 PM Page vi Adam Churvis: This book is dedicated to my uncle, Lionel Bernard Watkins II, and to the Marine Military Academy, for teaching me the most important Code of all. Semper Fidelis, Marines. Hal Helms: To Stan Cox, whose ideas never fail to inspire me. Charles Arehart: Begin to weave and God will give you the thread – German Proverb. David Churvis: I dedicate this book to Anne Granville, Neil Nichols, Pat Greeson, and Ed Coleman, the best schoolteachers I ever had. Thanks for never accepting anything less than my best and thanks for always believing in me. 546228 FM.F 1/31/03 3:07 PM Page vii 546228 FM.F 1/31/03 3:07 PM Page viii Preface ColdFusion has come a long way since its inception. Way back in 1995, AllaireCorporation came out with Version 1 of ColdFusion, and even then, develop- ers loved it and could see its potential. Several versions and one very important merger with Macromedia later, ColdFusion MX has positioned itself as a leading Web-application server, integrating many different Internet technologies, including XML, Web services, and Java. ColdFusion, at its core, is a server-side scripting environment that enables you to quickly get your sites up and running with much less code than the equivalent ASP, JSP, or PHP application requires but, at the same time, is even more powerful than these other languages. In fact, ColdFusion MX scripts are compiled into Java classes, and those Java classes are executed by an embedded version of JRun, Macromedia’s powerful J2EE server. This book is intended as a comprehensive tour of ColdFusion MX: It’s broad enough to give you a feel for everything that ColdFusion MX can do, but it’s deep enough that you can use the knowledge that you gain from this book to develop truly pow- erful ColdFusion applications. Whether you are a beginner or an expert, you should have the ColdFusion MX Bible in your reference library. How This Book Is Organized The scope of this book is rather broad and takes a natural progression, starting with a basic introduction, then moving on to using databases and the ColdFusion language itself before discussing more advanced concepts. The last part is the lan- guage reference, which has been organized very differently than most other refer- ences. There are nine parts to this book. Part I: Getting Started with ColdFusion MX The first part of the book incorporates seven chapters relating to the most basic aspects of ColdFusion. After a brief introduction, we provide a tutorial on building (and understanding) your first ColdFusion MX application. The rest of Part I focuses on the basics of the language itself, the underlying technology, and an intro- duction to using SQL effectively with ColdFusion. The last two chapters in Part I go into more detail about using forms and testing your code. 546228 FM.F 1/31/03 3:07 PM Page ix x ColdFusion MX Bible Part II: Using ColdFusion MX with Databases ColdFusion would be nearly useless without some kind of database as its backend. Part II starts with a chapter on database design, moves on to a discussion about using databases with ColdFusion, and then spends two whole chapters on effective and advanced database techniques. Even if you think that you know everything about databases, don’t skip this part of the book. Part III: The ColdFusion MX Language Part III focuses on the ins and outs of the ColdFusion language. The ten chapters in this section move from simple variables to complex variables such as arrays and structures before covering advanced topics such as user-defined functions, custom tags, state management, and exception handling. Part IV: ColdFusion MX Components, Web Services, and Flash Integration Part IV covers the new cutting-edge features of ColdFusion MX that can change the way that you write ColdFusion applications forever. The six chapters in Part IV should be read in order, because each builds on the concepts described in the pre- ceding chapter. Part IV starts out with two chapters about understanding and build- ing ColdFusion components and then discusses how and why you should move portions of your existing code to components. The last three chapters discuss Web services, Flash Remoting, and server-side ActionScript. Part V: Integrating ColdFusion MX with Other Technologies ColdFusion MX is most powerful if it’s extended with other technologies such as Java, COM, and XML. Part V consists of four chapters covering Java objects, JSP, EJB, COM, WDDX and XML, and some of the tags that ColdFusion uses to communi- cate with external systems. Spend some extra time on Chapter 30, as XML is about to become a big part of your development life. Part VI: Extending Your ColdFusion MX Applications Part VI covers additional features that you can use to extend ColdFusion, such as task scheduling, file operations, Verity, and charting, as well as some of the commu- nity resources and development tools that help make application development go much faster than normal. 546228 FM.F 1/31/03 3:07 PM Page x xiPreface Part VII: ColdFusion MX Development Practices Sometimes, how you code is as important as the code itself. Part VII covers important topics that are often overlooked, such as code documentation and testing, and also contains a discussion of Fusebox 3 written by none other than the Fusebox master himself, Hal Helms. The part also contains chapters about source-code control, effec- tive use of ColdFusion Studio, and integrating security into your applications. Part VIII: ColdFusion MX Administration Part VIII is comparatively short, but it’s packed with information about getting the most out of ColdFusion MX by tweaking its server settings. Part VIII is split into two chapters, the first covering all the settings available in ColdFusion Administrator and the second going into more detail about approaching specific settings and sets of options. Part IX: ColdFusion MX Language Reference Most language references use the format provided by Macromedia: an alphabetical listing of tags and functions (with tags separated from functions) and a separate list of categories. Part IX turns this model on its ear. Each section of the language (vari- ables, databases, forms, and so on) has its own chapter, and tags and functions are listed together in each chapter. This way, if you are working on a problem regarding database queries, you see all the tags and functions that are most often used to handle database queries in one place, which means that you nay also see what you’ve been missing in the language (such as, for example, CFOBJECTCACHE). If you need an alphabetical reference, we also provide a traditional alphabetized listing of all tags and functions with page references, and many tags cross-reference others so that, no matter what you’re looking for, you can easily find it. CD-ROM The CD-ROM that accompanies this book supplies you with a great deal of addi- tional material including author code listings and samples, many software applica- tions, and a PDF eBook version of the final book. The CD-ROM Appendix at the end of the book gives full details of all these items. 546228 FM.F 1/31/03 3:07 PM Page xi xii ColdFusion MX Bible How To Get The Most Out Of This Book Treat this book as you would a novel and not a cookbook. Most people, on picking up the ColdFusion MX Bible, would probably look up the one specific subject that they want to learn about and go directly there. Although this approach is certainly a valid one if you have a specific problem to solve, we recommend that, at some point, you start from the very beginning and work your way all the way through the book. If you are not a beginner, feel free to skip all of Part I but read everything after that. We recommend this approach even for advanced developers, because many people first starting out in ColdFusion unintentionally pick up some bad habits that remain with them even after they become better developers. The information contained in this book is based on sound development practices born of many years of experi- ence in many different languages and technologies. The first thing that we want to do is help you understand how ColdFusion works and how to get the most out of it, and the second is to make sure that no bad habits come back to haunt you. What the Icons Mean Throughout this book, you will find icons in the margins that highlight special or important information. Keep an eye out for the following icons: A Caution icon indicates a procedure that could cause difficulty or even data loss; pay careful attention to Caution icons to avoid common and not-so-common pro- gramming pitfalls. Cross-Reference icons point to additional information about a topic, which you can find in other sections of the book. A Note icon highlights interesting or supplementary information and often con- tains extra bits of technical information about a subject. Tip icons draw attention to handy suggestions, helpful hints, and useful pieces of advice. Tip Note Cross- Reference Caution 546228 FM.F 1/31/03 3:07 PM Page xii Acknowledgments We would like to take this opportunity to thank Sharon Cox, our AcquisitionsEditor, and Sharon Nash, our Project Editor, for making this project come together and for not making voodoo dolls of us when we missed submission deadlines. This book would not have achieved its high level of quality without the work diligently performed by its technical editors, Peter and Jen deHaan, and its copy editor, William Barton. If not for their dedicated involvement on these chapters, the end result would have been a book of measurably lower quality. We respectfully request to work with them again on all future Wiley books. We would also like to thank Alan Preston, Tom Donovan, and Raymond Camden at Macromedia for their excellent technical support and advice during the making of this book. Thanks also to the CFUG (ColdFusion User Group) and MMUG (Macromedia User Group) leaders who pour lots of unpaid hours into supporting their groups and the new technologies that Macromedia continues to give us. You are the backbone of the Macromedia development community, and the praises that you deserve would fill a book all by themselves. A special note of thanks to Michael Dinowitz, the father of the ColdFusion commu- nity, who has quite literally put his very life into the ColdFusion community. The countless hours that he has given us through developing and maintaining the House of Fusion Web site (www.houseoffusion.com) and its critically important mailing lists, the many speaking engagements that he has supported, and the father-like caring that he continues to have for everyone with a development prob- lem can never be sufficiently repaid. This praise is but a small token of what is due this truly admirable man. Behind every great man is a great woman, and Judith Dinowitz proves this axiom yet again. Judith’s tireless efforts running Fusion Authority (www.fusionauthority. com) have resulted in an accurate, up-to-the-minute account of everything ColdFusion on which many readers rely. And finally, thanks go out to you, the readers of this book, who make writing it all worthwhile. — Adam Churvis and David Churvis 546228 FM.F 1/31/03 3:07 PM Page xiii xiv ColdFusion MX Bible Thanks to my co-authors and to the indomitable folks at John Wiley & Son who made sure that you’re holding this book in your hands. — Hal Helms I can now appreciate better why so many authors thank their editors. What forbear- ance, with charm! Our two Sharon’s (Nash and Cox) were beacons in the night bringing this ship to port after more than 2 years at sea. Thanks too, of course, to Hal for bringing me on board initially and to Adam for captaining us through the rough seas. Last, and certainly not least, my love and inordinate gratitude to my wife Kim for her very own special patience through it all. — Charles Arehart 546228 FM.F 1/31/03 3:07 PM Page xiv Contents at a Glance Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Part I: Getting Started with ColdFusion MX. . . . . . . . . . . . . . . . . 1 Chapter 1: Introducing ColdFusion MX. . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2: Writing Your First ColdFusion MX Application . . . . . . . . . . . . . . 13 Chapter 3: Using ColdFusion MX Tags and Functions. . . . . . . . . . . . . . . . . 63 Chapter 4: Understanding Servers and Clients . . . . . . . . . . . . . . . . . . . . 77 Chapter 5: Learning a Little SQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Chapter 6: Using ColdFusion Forms . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Chapter 7: Testing Your Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Part II: Using ColdFusion MX with Databases . . . . . . . . . . . . . . 137 Chapter 8: Database Design Issues. . . . . . . . . . . . . . . . . . . . . . . . . . . 139 Chapter 9: Putting Databases to Work . . . . . . . . . . . . . . . . . . . . . . . . . 181 Chapter 10: Using Advanced Database Techniques . . . . . . . . . . . . . . . . . 205 Chapter 11: More Advanced Database Techniques . . . . . . . . . . . . . . . . . 251 Part III: The ColdFusion MX Language . . . . . . . . . . . . . . . . . . 289 Chapter 12: Understanding ColdFusion Variables . . . . . . . . . . . . . . . . . . 291 Chapter 13: Constructing Flow Control . . . . . . . . . . . . . . . . . . . . . . . . 305 Chapter 14: Creating Lists and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . 317 Chapter 15: Working with Structures . . . . . . . . . . . . . . . . . . . . . . . . . 333 Chapter 16: Scripting ColdFusion with CFSCRIPT . . . . . . . . . . . . . . . . . . 353 Chapter 17: Building User-Defined Functions. . . . . . . . . . . . . . . . . . . . . 363 Chapter 18: Writing Custom Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . 375 Chapter 19: Maintaining State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399 Chapter 20: Form Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 Chapter 21: Handling Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 429 Part IV: ColdFusion MX Components, Web Services, and Flash Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447 Chapter 22: Understanding ColdFusion MX Components . . . . . . . . . . . . . . 449 Chapter 23: Building Your First ColdFusion Components . . . . . . . . . . . . . . 487 Chapter 24: Migrating Custom Tags and UDFs to Components. . . . . . . . . . . 551 Chapter 25: Building Web Services with ColdFusion MX . . . . . . . . . . . . . . 557 546228 FM.F 1/31/03 3:07 PM Page xv Chapter 26: Flash Remoting Services . . . . . . . . . . . . . . . . . . . . . . . . . 569 Chapter 27: Using Server-Side ActionScript. . . . . . . . . . . . . . . . . . . . . . 591 Part V: Integrating ColdFusion MX with Other Technologies . . . . . 597 Chapter 28: Integrating ColdFusion MX and Java . . . . . . . . . . . . . . . . . . 599 Chapter 29: Integrating COM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 621 Chapter 30: Integrating ColdFusion MX with XML and WDDX . . . . . . . . . . . 637 Chapter 31: Communicating via Mail, FTP, and HTTP . . . . . . . . . . . . . . . . 681 Part VI: Extending Your ColdFusion MX Applications . . . . . . . . . 705 Chapter 32: Adding Useful ColdFusion MX Features to Your Application. . . . . 707 Chapter 33: Charting Data with ColdFusion MX . . . . . . . . . . . . . . . . . . . 729 Chapter 34: Leveraging Nifty Custom Tags . . . . . . . . . . . . . . . . . . . . . . 741 Chapter 35: Tools to Enhance the Development Environment . . . . . . . . . . . 751 Part VII: ColdFusion MX Development Practices . . . . . . . . . . . . 767 Chapter 36: Documenting Your Code . . . . . . . . . . . . . . . . . . . . . . . . . 769 Chapter 37: Fusebox Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 779 Chapter 38: Advanced Fusebox . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803 Chapter 39: Handling Source-Code Version Control . . . . . . . . . . . . . . . . . 845 Chapter 40: Integrating Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853 Chapter 41: ColdFusion Studio and HomeSite+ Tips and Tricks . . . . . . . . . . 873 Chapter 42: Testing and Performance . . . . . . . . . . . . . . . . . . . . . . . . . 897 Part VIII: ColdFusion MX Administration . . . . . . . . . . . . . . . . . 937 Chapter 43: An Overview of ColdFusion MX Administrator . . . . . . . . . . . . 939 Chapter 44: Configuration Tips and Tricks . . . . . . . . . . . . . . . . . . . . . . 969 Part IX: ColdFusion MX Language Reference . . . . . . . . . . . . . . 979 Chapter 45: Introduction to the Language Reference . . . . . . . . . . . . . . . . 981 Chapter 46: Designing Your Application Framework. . . . . . . . . . . . . . . . . 989 Chapter 47: General Use Tags and Functions . . . . . . . . . . . . . . . . . . . . . 991 Chapter 48: Working with Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 997 Chapter 49: Flow Control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1037 Chapter 50: Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 1047 Chapter 51: Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1051 Chapter 52: Databases and Queries . . . . . . . . . . . . . . . . . . . . . . . . . 1061 Chapter 53: Custom Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1071 Chapter 54: ColdFusion Scripting . . . . . . . . . . . . . . . . . . . . . . . . . . . 1073 546228 FM.F 1/31/03 3:07 PM Page xvi Chapter 55: Working with Systems Outside ColdFusion . . . . . . . . . . . . . . 1075 Chapter 56: Controlling Server Output and Whitespace . . . . . . . . . . . . . . 1087 Chapter 57: Verity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1091 Chapter 58: Mail. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1095 Chapter 59: Charting, Reporting, and Logging . . . . . . . . . . . . . . . . . . . 1099 Chapter 60: Files and Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . 1105 Chapter 61: The Registry. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1121 Chapter 62: Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1123 Chapter 63: Functions, Components, & Web Services . . . . . . . . . . . . . . . 1127 Appendix: What’s on the CD-ROM . . . . . . . . . . . . . . . . . . . . . . . . . . 1135 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1139 546228 FM.F 1/31/03 3:07 PM Page xvii 546228 FM.F 1/31/03 3:07 PM Page xviii Contents Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii Part I: Getting Started with ColdFusion MX 1 Chapter 1: Introducing ColdFusion MX . . . . . . . . . . . . . . . . . . . 3 Why a Tag-Based Language? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 ColdFusion Can Be Extended In Many Ways . . . . . . . . . . . . . . . . . . . 4 What You Need To Get Started . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 An Overview of What’s New in ColdFusion MX. . . . . . . . . . . . . . . . . . 6 Tag-based user defined functions . . . . . . . . . . . . . . . . . . . . . . 6 ColdFusion components . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Flash Remoting services . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Web services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Native XML handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Simplified security. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Simplified Verity administration . . . . . . . . . . . . . . . . . . . . . . . 9 Simplified locking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Java Server Pages integration . . . . . . . . . . . . . . . . . . . . . . . . 9 Extended graphing capabilities. . . . . . . . . . . . . . . . . . . . . . . 10 Enhanced query of queries . . . . . . . . . . . . . . . . . . . . . . . . . 10 Enhanced structured exception handling . . . . . . . . . . . . . . . . . 10 Enhanced debugging capabilities . . . . . . . . . . . . . . . . . . . . . 11 Enhanced regular expressions . . . . . . . . . . . . . . . . . . . . . . . 11 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Chapter 2: Writing Your First ColdFusion MX Application . . . . . . . 13 Your First ColdFusion Application . . . . . . . . . . . . . . . . . . . . . . . . 13 Some terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 What you’ll need . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Preparing your Web environment . . . . . . . . . . . . . . . . . . . . . 14 Setting up the database . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Planning Program Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Think in terms of processes . . . . . . . . . . . . . . . . . . . . . . . . 15 Think in terms of data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Setting Up the Framework For Your Application . . . . . . . . . . . . . . . . 16 546228 FM.F 1/31/03 3:07 PM Page xix xx ColdFusion MX Bible Adding a Company to the Database . . . . . . . . . . . . . . . . . . . . . . . 17 Building the company add form . . . . . . . . . . . . . . . . . . . . . . 17 Building the company add action template . . . . . . . . . . . . . . . . 19 The finished template . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 What just happened? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Getting a List of Companies . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Building the company list . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Using a SELECT statement . . . . . . . . . . . . . . . . . . . . . . . . . 25 Displaying the results of a query . . . . . . . . . . . . . . . . . . . . . . 25 Modifying a Company in the Database . . . . . . . . . . . . . . . . . . . . . . 26 Choosing a company to edit . . . . . . . . . . . . . . . . . . . . . . . . 26 Building the company edit form . . . . . . . . . . . . . . . . . . . . . . 27 Building the company edit action template. . . . . . . . . . . . . . . . 30 What just happened? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Removing a Company From the Database . . . . . . . . . . . . . . . . . . . . 33 Choosing a company to delete . . . . . . . . . . . . . . . . . . . . . . . 33 Creating the company delete form . . . . . . . . . . . . . . . . . . . . . 34 Confirming the deletion of a company before performing the action . . . . . . . . . . . . . . . . . . . . . . 36 Creating the company delete action template . . . . . . . . . . . . . . 36 Using a DELETE statement . . . . . . . . . . . . . . . . . . . . . . . . . 36 Adding a New Employee to the Database . . . . . . . . . . . . . . . . . . . . 36 Building the employee add form . . . . . . . . . . . . . . . . . . . . . . 37 Creating the employee add action template . . . . . . . . . . . . . . . 39 What was that CFSELECT tag? . . . . . . . . . . . . . . . . . . . . . . . 40 Getting a List of Employees . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 Creating the employee list . . . . . . . . . . . . . . . . . . . . . . . . . 41 Using DateFormat() to make the date look natural to the user . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Modifying an Employee in the Database . . . . . . . . . . . . . . . . . . . . . 43 Choosing an employee to edit . . . . . . . . . . . . . . . . . . . . . . . 43 Building the employee edit form . . . . . . . . . . . . . . . . . . . . . . 44 Creating the employee edit action template . . . . . . . . . . . . . . . 47 Removing an Employee From the Database . . . . . . . . . . . . . . . . . . . 47 Choosing an employee to delete . . . . . . . . . . . . . . . . . . . . . . 47 Building the employee delete form . . . . . . . . . . . . . . . . . . . . 48 Creating the employee delete action template . . . . . . . . . . . . . . 50 Creating a Launch Pad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Making Your Application Better. . . . . . . . . . . . . . . . . . . . . . . . . . 52 Creating a footer at the bottom of every page . . . . . . . . . . . . . . 52 Showing a company’s employees . . . . . . . . . . . . . . . . . . . . . 52 Making direct links to the add, view, and delete forms . . . . . . . . . 54 Redirecting the user back to the company list . . . . . . . . . . . . . . 56 Sending a welcome e-mail to a new employee . . . . . . . . . . . . . . 56 Setting a cookie in the employee list. . . . . . . . . . . . . . . . . . . . 57 Extending Your Application by Using a Custom Tag . . . . . . . . . . . . . . 59 Writing the custom tag . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Calling the custom tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Extending the custom tag with attributes. . . . . . . . . . . . . . . . . 60 546228 FM.F 1/31/03 3:07 PM Page xx xxiContents Congratulations!. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Chapter 3: Using ColdFusion MX Tags and Functions . . . . . . . . . . 63 ColdFusion Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Using operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Using function calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Pound Signs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Where and where not to use pound signs. . . . . . . . . . . . . . . . . 69 Knowing where and where not to use CFOUTPUT . . . . . . . . . . . . 71 How to escape pound signs . . . . . . . . . . . . . . . . . . . . . . . . . 72 Using CFOUTPUT blocks of code. . . . . . . . . . . . . . . . . . . . . . 73 How to Use Tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Empty tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Paired tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Shorthand closing syntax . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Chapter 4: Understanding Servers and Clients . . . . . . . . . . . . . . 77 What Is a Server, and What Is a Client?. . . . . . . . . . . . . . . . . . . . . . 77 CFML and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 Integrating CFML and JavaScript . . . . . . . . . . . . . . . . . . . . . . . . . 80 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Chapter 5: Learning a Little SQL . . . . . . . . . . . . . . . . . . . . . . 83 An Overview of Relational Databases . . . . . . . . . . . . . . . . . . . . . . 83 An Overview of Structured Query Language (SQL). . . . . . . . . . . . . . . 87 SELECT Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 INSERT Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95 UPDATE Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 DELETE Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 Chapter 6: Using ColdFusion Forms. . . . . . . . . . . . . . . . . . . . 109 Implementing Client-Side Validation . . . . . . . . . . . . . . . . . . . . . . 109 Using CFINPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Where you cannot use CFINPUT . . . . . . . . . . . . . . . . . . . . . 111 Using CFSELECT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Using check boxes and radio buttons . . . . . . . . . . . . . . . . . . 114 Implementing Server-Side Validation . . . . . . . . . . . . . . . . . . . . . . 116 Graphical User Interface Widgets . . . . . . . . . . . . . . . . . . . . . . . . 117 CFSLIDER. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 CFTEXTINPUT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 CFTREE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Populating a CFTREE control from a query . . . . . . . . . . . . . . . 119 CFGRID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 546228 FM.F 1/31/03 3:07 PM Page xxi xxii ColdFusion MX Bible The Caveats of Using CFFORM. . . . . . . . . . . . . . . . . . . . . . . . . . 123 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Chapter 7: Testing Your Code. . . . . . . . . . . . . . . . . . . . . . . . 125 Development Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Test harnesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 Unit testing with bad data . . . . . . . . . . . . . . . . . . . . . . . . . 126 Structured exception handling . . . . . . . . . . . . . . . . . . . . . . 127 Application testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 How to test your application . . . . . . . . . . . . . . . . . . . . . . . 128 Testing your application with bad data . . . . . . . . . . . . . . . . . 129 Browser woes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 Empty-nest testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Regression testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Load testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Debugging Your Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Debug settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Using CFDUMP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 The integrated debugger. . . . . . . . . . . . . . . . . . . . . . . . . . 135 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Part II: Using ColdFusion MX with Databases 137 Chapter 8: Database Design Issues . . . . . . . . . . . . . . . . . . . . 139 Relational Database Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139 What is a “relational database?” . . . . . . . . . . . . . . . . . . . . . 139 Describing relationships . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Types of Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Creating your physical data model . . . . . . . . . . . . . . . . . . . . 152 Referential integrity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Denormalization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 Defaults. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Check constraints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Creating a Scalable Database. . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Index design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 Data Description Language (DDL) . . . . . . . . . . . . . . . . . . . . 170 Don’t try to get OLAP out of an OLTP database . . . . . . . . . . . . . 178 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 Chapter 9: Putting Databases to Work . . . . . . . . . . . . . . . . . . 181 Understanding All Relational Result Sets . . . . . . . . . . . . . . . . . . . . 181 How to Visualize What is Possible and Impossible Within an SQL Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 188 SQL’s processing order of precedence . . . . . . . . . . . . . . . . . . 189 How and when to use GROUP BY, HAVING, and DISTINCT. . . . . . . 194 546228 FM.F 1/31/03 3:07 PM Page xxii xxiiiContents Structured Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . 198 Query Caching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Watch your memory! . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 You can’t use CFQUERYPARAM . . . . . . . . . . . . . . . . . . . . . . 203 Caching stored procedures . . . . . . . . . . . . . . . . . . . . . . . . 203 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Chapter 10: Using Advanced Database Techniques . . . . . . . . . . 205 Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205 Understanding transactions . . . . . . . . . . . . . . . . . . . . . . . . 206 Where to control a transaction . . . . . . . . . . . . . . . . . . . . . . 207 CFTRANSACTION and exception handling. . . . . . . . . . . . . . . . 209 Transaction isolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 Horizontal and vertical masking . . . . . . . . . . . . . . . . . . . . . 215 Relational views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Precompiling queries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Enhancing security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Caveats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Stored Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 What is a stored procedure?. . . . . . . . . . . . . . . . . . . . . . . . 218 The three components of calling a stored procedure . . . . . . . . . 223 Oracle stored procedures and packages. . . . . . . . . . . . . . . . . 232 Practical things that you can do in using stored procedures . . . . . 242 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Chapter 11: More Advanced Database Techniques. . . . . . . . . . . 251 Triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 Triggers and implicit transactions . . . . . . . . . . . . . . . . . . . . 252 Where DRI constraints alone just don’t do . . . . . . . . . . . . . . . 254 Getting the database to do the work for you . . . . . . . . . . . . . . 258 Affecting single and multiple rows . . . . . . . . . . . . . . . . . . . . 260 Instead-Of triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 Oracle triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267 Practical things that you can do by using triggers . . . . . . . . . . . 270 Eliminating the Need for Post-Processing Data Within ColdFusion . . . . . 273 Effective Use of ColdFusion MX’s Enhanced Query of Queries . . . . . . . 275 Performing relational joins between ColdFusion query objects . . . 276 Querying a query object . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Caveats and restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Don’t be tempted to post-process data . . . . . . . . . . . . . . . . . 280 Getting multi-dimensional results. . . . . . . . . . . . . . . . . . . . . 280 Leveraging QoQ by using query caching. . . . . . . . . . . . . . . . . 284 Data Binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 CFQUERYPARAM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Caveats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 546228 FM.F 1/31/03 3:07 PM Page xxiii xxiv ColdFusion MX Bible Part III: The ColdFusion MX Language 289 Chapter 12: Understanding ColdFusion Variables . . . . . . . . . . . 291 What Is Meant By Scope? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291 Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 The Variables scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 The Attributes scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293 The Caller scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Nonpersistent global variables . . . . . . . . . . . . . . . . . . . . . . 294 Persistent global variables. . . . . . . . . . . . . . . . . . . . . . . . . 296 Testing for Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 Chapter 13: Constructing Flow Control . . . . . . . . . . . . . . . . . . 305 If/ElseIf/Else Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Switch/Case Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306 Loop Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 Looping a specified number of times. . . . . . . . . . . . . . . . . . . 308 Looping while a condition is true . . . . . . . . . . . . . . . . . . . . . 309 Looping over a query. . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Looping over a list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Looping over a structure. . . . . . . . . . . . . . . . . . . . . . . . . . 311 Breaking out of a loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 311 Including One Template’s Code in Another . . . . . . . . . . . . . . . . . . 312 Redirecting the User to a Different Location . . . . . . . . . . . . . . . . . . 314 Stopping a Page’s Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Chapter 14: Creating Lists and Arrays . . . . . . . . . . . . . . . . . . 317 Using Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317 Creating a list . . . . . . . . . . . . . . .

Các file đính kèm theo tài liệu này:

  • pdfcoldfusion_mx_bible_01_1767.pdf
Tài liệu liên quan