Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..
SYS-CON.TV
Today's Top SOA Links


Hidden Gems
Hidden Gems

With all the talk and buzz surrounding Neo, it's important to keep in mind that ColdFusion 5 is still a relatively new product, one that many users have yet to take full advantage of. We're proud of ColdFusion 5, and rightfully so. It's the most reliable, most scalable, and most powerful ColdFusion yet, as well as the fastest server we've ever created. It's simply the best ColdFusion to date.

Although I've dedicated numerous columns this year to ColdFusion 5, I thought it worthwhile to do it once more, this time concentrating on some of the little features and enhancements that many have overlooked - features and enhancements that truly are hidden gems.

Inspecting Variables and Expressions
When debugging ColdFusion applications, it's almost always necessary to inspect the contents of variables. Simple variables can be dumped easily to screen using just a <CFOUTPUT>, like this:

<CFOUTPUT>#var#</CFOUTPUT>

But more complex variables can't be displayed that way. Arrays must be looped through, structures must be expanded, queries must be processed one row at a time, and so on. And it gets worse. Really complex variables (perhaps a structure containing an array of structures containing arrays or queries, or something like that) present developers with complicated coding challenges - not the kind of thing you want to tackle while trying to debug code. And then you need to worry about UI and presentation of this data.

Well, not anymore - I'd like to introduce you to your new debugging partner, the <CFDUMP> tag. Originally created for Spectra, this tag became so popular and useful that it made its way back into ColdFusion in CF5. So what does <CFDUMP> do? Simply put, <CFDUMP> dumps expressions, any expressions, to screen in a clean DHTML-based table. Consider this example:

<CFDUMP VAR="#fname#">

ColdFusion will display an HTML table with the variable name on the left and its value on the right.

The next example is just as simple to invoke, but SESSION.cart is actually a shopping cart structure containing an array of selections. <CFDUMP> displays all the contents in a table that can be collapsed and expanded as needed:

<CFDUMP VAR="#SESSION.cart#">

Any data can be dumped with <CFDUMP>. The next example displays all SESSION variables for the active SESSION (SESSION is a structure internally). And if one of those SESSION variables were SESSION.cart, then all of the nested data within that variable would be displayed as well:

"CFDUMP VAR="#SESSION#">

<CFDUMP> is a powerful tool, and easy to use, one that you'll wonder how you lived without.

Client-Side Regular Expression Validation
Next is one of my favorite ColdFusion 5 features. It's also one of the least known (I don't think Macromedia has even mentioned it on feature lists; the only place you'll find it is in the CFML tag docs).

You're probably familiar with <CFINPUT>, the form tag that can be used to perform client-side form validation using automatically generated JavaScript code. <CFINPUT> is very useful, but it has one serious limitation - it can't be extended easily. Let me explain: if you need to flag a field as required, if you need to validate a U.S. phone number, if you need to validate a date, then <CFINPUT> works well. But if you need to validate anything that isn't one of the supported validation types - e-mail addresses, non-U.S. phone numbers, required minimum value lengths, for example - then <CFINPUT> falls flat on its face.

Or rather, it used to. In ColdFusion 5 <CFINPUT> has been extended to let you validate just about anything you can imagine. How? By adding one new validation type, Regular Ex-pressions. In CF5 you may use a Regular Expression pattern as the validation rule for your field. ColdFusion will generate the needed JavaScript so the browser won't validate the form field unless the value matches the specified Regular Expression.

Let's look at an example. I recently created a form that had to prompt for RGB values (colors specified in amounts of red, green, and blue). RGB values are six characters long - three sets of two hexadecimal values (00 to FF). My form had three text fields, one for each of the three values. Here's the <CFINPUT> used for the first one:

<CFINPUT TYPE="text"
NAME="color_r"
VALIDATE="regular_expression"
PATTERN="[A-Fa-f0-9]{2,}"
MESSAGE="RGB value must be 00-FF"
SIZE="2"
MAXLENGTH="2">
As you can see, I used VALIDATE="regular_expression" and then provided the Regular Expression to use in the new PATTERN attribute. [A-Fa-f0-9] matches a single character of A through F (upper or lower case) or 0 through 9. The {2,} instructs the browser to accept a minimum of two instances of the previous expression. That, coupled with MAXLENGTH="2", and I have a perfect validation rule.

Here's another one - one we probably all wish were a built-in rule. It validates that an e-mail address is formed correctly:

<CFINPUT TYPE="text"
NAME="email"
VALIDATE="regular_expression"
PATTERN="[A-Za-z0-9_]+@[A-Za-z0-9_]+\.[A-Za-z]+"
MESSAGE="Please enter a valid E-Mail address">
Here the Regular Expression matches one of more alphanumeric characters (or an underscore) followed by an @ sign, followed by one or more alphanumeric characters (again allowing underscores), followed by a period, then followed by one or more alphanumeric characters. This won't actually check that a specified e-mail address is a valid working address, but it will at least prevent completely invalid addresses from being entered.

As you can see, with minimal work you can write Regular Expressions to validate all sorts of things. <CFINPUT> is limited no longer.

Note: The Regular Expressions used here aren't the same as those used in the CFML RE functions. The Regular Expressions passed to <CFINPUT> are those supported by JavaScript.

Better Log File Use
ColdFusion creates log files. Lots of them. With lots of entries in each. Log files are an invaluable debugging and troubleshooting tool - if you're able to find just the entries you need, and if you can work out what the user was doing before the log entry was generated.

That's where the new <CFLOG> tag comes in. <CFLOG> lets you write your own entries to log files (either the standard log files or your own). Look at this example:

<CFLOG APPLICATION="yes"
TEXT="User name is #user.name#">
This code writes the log text to the Application.log file. If a particular line of code were generating an error, you could insert a <CFLOG> call like this above it so that when browsing the log file you'd have enough information to properly diagnose the problem. When used in conjunction with CF5's new log viewer (in the ColdFusion Administrator), <CFLOG> makes those large log files far more manageable and accessible.

Accessing HTTP Data
ColdFusion provides access to all sorts of server, client, and environmental data via CGI and other variables. But have you ever wanted access to data not explicitly made available? If so, you must have discovered that there really is no way to get to it.

Until now. New to ColdFusion 5 is the GetHTTPRequestData() function, which exposes any and all HTTP data. Here's the function call:

<CFSET data=GetHTTPRequestData()>
GetHTTPRequestData() returns a structure containing headers, raw content, server information, and more. To display the raw content you could simply do this:

<CFOUTPUT>
#data.content#
</CFOUTPUT>
The structure also contains a second structure, names headers. You can loop through or search this structure to access every header and value. In other words, using GetHTTPRequestData(), you now have access to any and all relevant data.

Summary
ColdFusion 5 has lots of great new features that I've covered in previous columns - things like user-defined functions, graphing, querying queries, server probes, and so on. But just as compelling as these marquee features are all the little enhancements, many of which just slipped into the product with no fanfare at all.

As I stated at the start of this column, ColdFusion 5 is simply the best ColdFusion to date. If you haven't upgraded yet, do so quickly. And if you're already running CF5, look for the little features and enhancements that can make your development easier and more productive. I listed just four here. If you find others you think are significant, let me know.

About Ben Forta
Ben Forta is Adobe's Senior Technical Evangelist. In that capacity he spends a considerable amount of time talking and writing about Adobe products (with an emphasis on ColdFusion and Flex), and providing feedback to help shape the future direction of the products. By the way, if you are not yet a ColdFusion user, you should be. It is an incredible product, and is truly deserving of all the praise it has been receiving. In a prior life he was a ColdFusion customer (he wrote one of the first large high visibility web sites using the product) and was so impressed he ended up working for the company that created it (Allaire). Ben is also the author of books on ColdFusion, SQL, Windows 2000, JSP, WAP, Regular Expressions, and more. Before joining Adobe (well, Allaire actually, and then Macromedia and Allaire merged, and then Adobe bought Macromedia) he helped found a company called Car.com which provides automotive services (buy a car, sell a car, etc) over the Web. Car.com (including Stoneage) is one of the largest automotive web sites out there, was written entirely in ColdFusion, and is now owned by Auto-By-Tel.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE