In: Categories » » Programming » ColdFusion Can Be Extended In Many Ways
In addition to being one of the easiest Web-programming languages, ColdFusion is also one of the most easily extensible languages, because it can interface with many different technologies, as shown in the following list:
Java objects, which are standalone packages of code written in the Java language
Custom tags written in C++ or Java, which are pieces of code to be used only with ColdFusion, but which are written in either C++ or Java
Java Server Page (JSP) tag libraries, which are originally built for use within JSP systems
Java Server Pages, which are the JSP equivalent of ColdFusion templates
Flash Remoting, which enables ColdFusion to easily communicate with Flash movies
Web services, which publish portions of a ColdFusion application’s functionality for use by other application servers, including non-ColdFusion servers
COM (Component Object Model) objects, which are software objects that can communicate with one another on the Microsoft Windows platform
CORBA (Common Object Request Broker Architecture) objects, which can communicate with one another over networks and between platforms
The operating system (Windows, Unix, and so on), through batch files and executables Each of these technologies can and do take up entire articles by themselves, because they are big topics. ColdFusion, however, makes integrating them with your application a relatively simple matter by using a simple interface—usually just a matter of one or two CFML tags. For more information about extending ColdFusion. In addition, refer to Developing Web Applications with ColdFusion MX in your ColdFusion MX documentation set to learn about creating CFX custom tags, which are custom tags written in Java or C++ for use in ColdFusion.
The following list describes what you need before you begin:
A copy of ColdFusion MX Server.
A copy of HomeSite, HomeSite+, Dreamweaver MX, ColdFusion Studio, or another code editor. You can acquire a trial copy of HomeSite from Macromedia at www.macro media.com/software/homesite/.
Database software. We provide an Access database for Part I of this article, but if you have Microsoft SQL Server, Oracle, or another Enterprise-level database server, by all means use it after you get past building your first ColdFusion application. That’s all you need to begin developing applications in ColdFusion MX. Follow the installation instructions for ColdFusion MX very carefully and make certain that you heed any warnings during the install process. Our advice is to go very slowly through the installation process and keep your finger off the mouse button so that you don’t anxiously click Next before reading important instructions. You shouldn’t just “slam through the defaults” in installing ColdFusion MX either, because you have important choices to make regarding your Webserver configuration. For example, ColdFusion MX can install its own standalone web server for development purposes during the installation process, or it can use your currently installed web server, so watch what you’re doing.
The MX release of ColdFusion is without doubt the most eagerly anticipated software release in Macromedia’s history. Everything—every single thing—has been completely rewritten from the ground up, in Java. Not only that, but the ColdFusion software itself now runs on top of JRun, Macromedia’s J2EE server engine. You still write your ColdFusion applications in CFML, but behind the scenes, ColdFusion Server translates your CFML into Java source code, compiles it into Java bytecode, and then JRun kicks in and runs the compiled Java byte code. This whole translation-and-compilation process is entirely transparent to you, but the performance gains are very obvious in most cases. Along with these changes in platform and architecture came big enhancements in the ColdFusion language and some truly powerful new technologies, some of which change the very way that you write ColdFusion applications from now on. ColdFusion components, also known as CFCs, bring some object-like behavior to ColdFusion. In their simplest implementation, components are formal containers for interrelated functions created by using CFFUNCTION. By encapsulating all functions related to a specific process or entity in a single component, you take your first step toward thinking in terms of objects rather than in terms of individual pieces of code. Components can also be implemented as persistent objects that “live” between page requests and contain both user-defined functions and properties (data). ColdFusion components are not true objects, as you find in other languages such as Java or C++, but they do enable some “object-like” capabilities, such as basic inheritance. Powerful new functionality in ColdFusion MX, such as Web services and Flash Remoting, use ColdFusion components as well. For anyone who has succeeded in interfacing Flash movies with ColdFusion, MX’s new Flash Remoting Services are a true godsend. What used to require a good bit of knowledge in Flash ActionScripting (the language of Flash), plus hours or days of laboring in Flash and ColdFusion MX, now takes only a basic understanding of ActionScript and a few lines of code to link a Flash movie with ColdFusion. If you’re new to ColdFusion, you’ll still be amazed at how easy Flash Remoting makes creating Flash movies that use the functionality built into your ColdFusion applications. Where earlier versions of Flash were basically crude animation tools that could be forced into exchanging data with ColdFusion, Flash Remoting turns the Flash MX authoring environment into a true client-application development environment that is designed from the ground up to work directly with ColdFusion MX. Flash MX applications communicate with ColdFusion by using a new and very efficient binary format named AMF (Action Message Format), which is not only faster but requires only a fraction of the bandwidth previously taken up by XMLbased data exchanges. Flash Remoting enables you to develop applications with truly interactive graphical user interfaces. The best that you could do before Flash Remoting came along was to create an overly complicated DHTML convolution that either cached data locally or made constant page requests from ColdFusion each time that the user touched a form control. If you are interested in developing serious Flash MX applications—and we hope that you are—you should also obtain the Flash MX Action Script Bible, by Robert Reinhardt and Joey Lott (Wiley Publishing) and digest it thoroughly. I recommend this article not because it comes from the same publisher as this one, but because Robert Reinhardt and Joey Lott have done an excellent treatment of Flash MX that should not be missed.
A Web service exposes a software component to remote systems in a platform-independent manner, meaning that any application server platform capable of consuming web services can make use of the web services created with ColdFusion MX. ColdFusion MX truly rang the bell with its implementation of Web services: To create a Web service in MX, you simply set the Access attribute of a ColdFusion component function to Remote. No, really! You need to pay attention to a few details, of course, but creating a Web service is a natural extension to ColdFusion’s component functionality. Whenever a ColdFusion component is accessed as a Web service, the remote consumer of the Web service receives the result in the native format of the consumer’s platform, so .NET consumers receive ColdFusion arrays as .NET arrays, and Java consumers receive them as Java arrays. Some incompatibilities do exist between certain ColdFusion complex data types and specific consumer platforms, but these hurdles can be cleared by exchanging complex data as XML documents that the consumer may then transform as needed. One piece of advice: Learn Web services, XSLT transformations, and how to validate XML documents against DTDs by using COM. These skills may sound foreign to you now, but they’re soon to be in very high demand, and we want you there to provide the necessary solutions. Finally, ColdFusion can handle XML! If you’ve never heard of it before, XML stands for eXtensible Markup Language, and it provides a way to structure data and encode it with additional information using a plain text format that can be used by most modern application servers and applications. Previously, data interchange with XML was limited to one of the following two options in ColdFusion:
Use WDDX as an interchange format: This was a good start, but it was limited because you were locked in to a data-centric flavor of XML.
Use a COM object or third-part custom tag library: Some good libraries were on the market, but they still are no match for the capability to natively use XML and XML objects. Now, by using ColdFusion MX, all you need do to create an XML object is use the new CFXML tag, as follows:
<cfxml variable=”XmlObj”> <my-xml-tag> <my-child-tag /> </my-xml-tag> </cfxml>
And that’s only the beginning of an impressive array of XML handling features; in fact, the only feature missing from ColdFusion’s XML implementation is the capability to validate against a DTD or XMLSchema document, which can be easily remedied by using COM. For more information about validating XML with ColdFusion MX. ColdFusion MX also natively handles XSLT transformations, so you can transform structured XML documents into virtually any type of content. MX’s XPath capabilities enable you to query an XML object and extract data structures that match search criteria. After you parse an XML document into an XML object, you can refer to its data elements by using the same ColdFusion syntax used for handling arrays and structures, so your learning curve remains relatively small.
Does anyone remember Advanced Security? Does anyone want to suffer through that again? ColdFusion MX makes security easier to manage in two ways: application security by using the new CFLOGIN tag (and its related tags and functions) and the new J2EE-integrated Sandbox Security. ColdFusion MX introduces CFLOGIN, which solves two problems at once. First, it’s easy to use and understand, so it takes less development time than a roll-your-own solution. Second, and perhaps more important, CFLOGIN integrates directly with J2EE security, which is a proven security framework that can integrate with other J2EE products. Integrating with J2EE security means that a user can log in to a ColdFusion Web site and have that same login honored by a call to an EJB (Enterprise JavaBean) or a JSP page. This is very powerful stuff. Available only in the Enterprise version of ColdFusion MX (although Professional has a similar feature, named Resource Security), Sandbox Security is a great feature for shared hosts or people running a department with multiple applications, because it enables a site administrator to restrict what resources the code on his server can access. The administrator can, for example, restrict the code in one directory from accessing specific tags and datasources, and he can restrict code in another directory from accessing a completely different set of tags and datasources. Verity is the name of the company who invented the full-text search technology use by ColdFusion MX, so full-text searching in ColdFusion is commonly referred to as “Verity searching.” A full-text search is what you perform on popular search sites like Google and Yahoo, where you can search for a word or phrase, the search engine looks inside collections containing billions of web pages for that word or phrase, and returns a weighted list of results that most likely best fit what you’re looking for. Expansions to the Verity full-text search system have made managing a site that uses Verity easier than ever. You can now obtain a list of all the Verity collections on your server (as well as some extra metadata, such as where they are stored and whether they are K2 Server (a high performance standalone Verity server) collections) by using the CFCOLLECTION tag, as follows:
<cfcollection action=”LIST” name=”GetCollections”>
ColdFusion MX offers new Verity-related functions and still more improvements over earlier versions of ColdFusion. Because ColdFusion MX is now built on Java, you no longer need to worry about data corruption in the shared memory scopes: Session, Application, and Server. Unfortunately, this fact has been misinterpreted by some to mean “Hey—I don’t need to lock my Session variables anymore!” Nothing can be farther from the truth. You still need to lock shared memory scopes to prevent what are known as race conditions, where one piece of code may interfere with another that is also trying to access the same data in shared memory. Race conditions are more prevalent than you may think; all in all, you’re most likely to continue to lock shared memory scopes almost as much as you did in earlier versions of ColdFusion. The new locking rules do enable you to safely read and write “write-once” variables in shared memory scopes without locking. So if you have a Session variable that is created only once during a session, is never destroyed and recreated, is never modified under any conditions whatsoever, and is never CFSET a second time—even with the same value that it had previously —you do not need to lock access to it. ColdFusion MX is built on top of the same platform that runs JSP (or Java Server Pages). You can, therefore, include JSP pages in your application, and you can share variables between ColdFusion and JSP! We can set a Session variable, for example, in MyCFPage.cfm as follows:
<cfset Session.myvar = 1>
And we can then output it on MyJSPPage.jsp as follows:
<%= session.getAttribute(“myvar”) %>
This example may illustrate only the general principle behind sharing data between the two platforms, but imagine the possibilities. For more information about integrating ColdFusion with Java technologies. ColdFusion’s integrated charting capabilities received an overhaul in the MX release, so much so that, instead of upgrading the existing ColdFusion 5 CFGRAPH tag, Macromedia replaced it with a new CFCHART tag. You can now create charts that were totally impossible before, such as the following list describes:
Multiple series on a chart
3D charts with full control over the rotation effects
New chart types, such as area, pyramid, and scatter charts
New point markers
PNG output instead of GIF
Value rollovers that now work with PNG or JPG formats
Improved Flash output
Better control over value formats
And these are just some of the new features! CFCHART’s output is also much more attractive than CFGRAPH’s was. Introduced with much fanfare in Version 5, Query of Queries (or QoQ as the feature is sometimes called) was a great idea. It enables you to get data from multiple sources (whether from the database, file structure, or anything that returns a query object to ColdFusion) and combine them into a single result set. The problem was that QoQ was clumsy and couldn’t do much. ColdFusion MX has enhanced its QoQ processor. The SQL used to manipulate QoQ is now a little more natural and less restrictive. You still have no outer join capability, and you still can’t alias (provide a different and usually abbreviated name for) the names of tables, but you now don’t need to alias the names of columns to retrieve them, and you can now match NULLs, which was impossible before.
Structure exception handling provides a framework within which your code operates, such that, if an error is thrown, it may be interrupted and either handled using alternative code (this is known as an “exception”), or logged and the user politely notified that an error has occurred. Structured exception handling also received an overhaul in ColdFusion MX—so much so that you can now catch and throw native Java exceptions from your ColdFusion code; in fact, you can even create your own Java exception objects and throw them as well. In addition, more exception information is available if an error is thrown now, and more types of errors can be thrown. Another excellent exception handling feature is the new CFSCRIPT-based exception handling, which gives you limited try/catch capability within a CFSCRIPT block. ColdFusion’s debugging capabilities were also seriously improved in ColdFusion MX. The debug output is much more in-depth and is now available in a cool new graphical format. You also get a new CFTRACE tag that you can use to watch variables and/or trace execution time. The traditional debugging capabilities are also improved in ColdFusion MX. CFDUMP now has a much better format, and it no longer puts the names of structure keys in all caps. CFLOG, because most of its attributes are deprecated now, has become simpler to use, because you need only a few attributes to create an effective, detailed log. A regular expression is a formula for describing a pattern within a string. String patterns can be very large and complicated, like an email message header, or small and simple, like an email address. Regular expressions have always been the powerhouse of any string-parsing or data-processing application. ColdFusion 5 and earlier versions had a good implementation of regular expressions, but they suffered because ColdFusion 5 didn’t support some important advanced features. ColdFusion MX has turned this on its ear by introducing some of Perl 5’s most advanced regular-expression capabilities, including the following:
Nonmatching expressions (using ?: in front of a subexpression)
Positive lookahead (using ?= in front of a subexpression)
Negative lookahead (using ?! in front of a subexpression)
Comments in regular expressions (using ?x in front and using ## for a comment)
Improved buffer operators (which can now work in multiline mode)
Improved character-set matches
Regular expressions within ColdFusion now offer everything that even the most advanced regular-expression engines do. The only capability missing from ColdFusion’s regular expressions is lookbehind, a feature so rarely implemented that its omission is understandable. If you have been exposed to ColdFusion before and are just reading this article to find out what’s new, you are probably amazed at what MX has to offer. As you’ve seen in this article, the MX release of ColdFusion Server truly vaults it to the Enterprise level with its J2EE-based platform, native XML handling, Web services, and more, as well as its extensibility through other technologies. If you’re just starting in ColdFusion but you’ve been exposed to other languages, you’re going to love ColdFusion MX not only for its simple syntax and ease of use, but also for what’s built right into the language. Most other languages use third-party tools for features such as XML, Web services, and charting, but ColdFusion has them all built right in. And if you’re just beginning your Web-development career, ColdFusion is probably the best place to start. It’s simple, so it gets you up and running much faster than other languages do. It also has the best developer community of any programming language that we’ve seen, so getting your questions answered is easy, too.
legal notice
Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.
Useful tools and features
related articles
The code in CompanyEditAction.cfm is like the code in CompanyAddAction.cfm, but the edit action updates rather than inserts. Create a file named CompanyEditAction.cfm inside the Ch02 directory, type the code into the file’s editing window, and save the file. <cfquery name=”UpdateCompany” datasource=”#Request.MainDSN#”> UPDATE Company SET CompanyName = ‘#Trim(Form.CompanyName)#’, Address = ‘#Trim(Form.Address)#’, City = ‘#Trim(Form.City)...
2. Adding a New Employee to the Database
The CFQUERY in CompanyDeleteAction.cfm uses a DELETE statement with two SQL clauses: DELETE and WHERE. DELETE tells the database the table from which to delete a record, and WHERE tells the database which record to delete. You can watch the company delete process in action. Point your Web browser to http://<yourserver>/CFMXBible/Ch02/CompanyGetDeleteForm.cfm and enter a CompanyID. (To get a valid ID, go to the company list and pick a number from the ID column.) Click Submit to see the chosen company’s informatio...
3. Modifying an Employee in the Database
The DateFormat() function around the DateOfBirth column in the codereturns the employee’s birth date reformatted according to a display mask. DateOfBirth normally comes back from the database in the following format: 2002-01-01 00:00:00.0 That format is not very user-friendly. Calling DateFormat() with a mask of “mm/dd/yyyy” returns the date as follows: 01/01/2002 This version is, of course, more natural and easy to read. The same is true for the employee edit process...
4. Removing an Employee From the Database
The user must have the capability to remove employees from the database. The employee delete process is a simple combination of techniques that you have already learned, such as retrieving a record from the database, displaying that record in a template, and so on. The first page in this process is nearly identical to the employee get edit form. Create a file named EmployeeGetDeleteForm.cfm inside the Ch02 directory, type the code into the file’s editing window, and save the file. <html> <head> <ti...
5. Making direct links to the forms
Say that you want to modify or delete a company. Right now, you need to remember the company’s ID, go back to the launch pad, click Company Edit, and enter the company ID, all just to get to the edit form. Wouldn’t you rather click a company in the list and go directly to the edit form? ... <table> <tr> <td><b>ID</b></td> <td><b>Name</b></td> <td><b>Address</b></td> <td><b>City</b></t...
6. Using a Custom Tag
Custom tags are reusable, developer-authored extensions to the ColdFusion language. The custom tag that you create in the following parts displays today’s date in a familiar format. Create a file named TodaysDate.cfm inside the Ch02 directory, type the code into the file’s editing window, and save the file. <cfoutput>#DateFormat(Now(), “ddd, mmm d, yyyy”)#</cfoutput> Now() returns the current date and time, and DateFormat() reformats the date. To call your custom tag, open index.cfm, a...
7. Creating your physical data model
Physical data models are extracted from their logical counterparts by mapping logical objects to physical objects supported by the target database platform. The following table shows the relationship between logical and physical objects. In many cases, your physical data model almost mirrors your logical data model because entities typically map directly to the tables that store them. Exceptions to this rule are logical data models that contain nonspecific relationships and entity subtypes. Although entity subtypes are an advanced top...
