Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex

Adobe Flex: Article

CF Explained

CF Explained

For those of you who don't know who I am, let me begin by explaining that I am not a designer. I can't make pages or pictures pretty - heck, I haven't even figured out how to use some of the features in PC Paint yet. My expertise is in software architecture, programming, and business logic. In Web terms, I make all the stuff that runs on the server - the stuff that isn't displayed in Web pages. My tool of choice for doing this is Macromedia's Coldfusion Application Server. In addition to building applications with Coldfusion, I tech edit and write for Coldfusion Developer's Journal(CFDJ).

Well, when the folks at SYS-CON Media (the publishers of CFDJ and many other magazines, including the one you're holding right now) told me about MXDJ - one magazine to cover all of the Macromedia Studio MX products - I thought, "Who, me? Read articles about Fireworks MX, Director, and FreeHand MX? Yeah right. That's all I need... to try and wrap my head around more new technologies and IDEs."

But the more I thought about it the more I felt that maybe I really do need to better familiarize myself with the more "design-oriented" Macromedia products. After all, two years ago I detested the idea of writing code with Dreamweaver and now I use it all the time. Two years ago I also thought that the closest I'd ever come to doing Flash would involve a trench coat and being chased by the police.

Now I love working with Flash (but I'm still no designer). I also thought about the fact that design tools are so scary for developers, and that designers could very easily feel the same way about ColdFusion. The purpose of this article is to explain what ColdFusion MX is, how it works, and what its place is among the other Macromedia MX products, to all of the MXDJ readers who are unfamiliar with it. I'll begin by explaining exactly what ColdFusion is.

CF Works on the Server
ColdFusion is an application server - by that I mean that you install it on your server and it does all of its work on the server. You can think of it as being similar to a Web server. Web servers sit on the network and wait for an HTTP request. When somebody tells their Web browser to go to a specific URL, the Web server receives this request, finds the file (usually an image, HTML, CSS, or JavaScript file), and sends the contents of that file back to the Web browser. The browser parses what the server sends it and renders the contents for the end user. Thus, the browser is doing most of the work and the Web server is acting as a file server, nothing more.

In the case of ColdFusion, when a browser sends a request to the Web server and the request is for a page written in CFML (ColdFusion Mark-up Language - the programming language used in ColdFusion pages), rather than sending the contents of that file to the browser, the Web server hands the request off to the ColdFusion Application Server. The ColdFusion Application Server then opens the file and parses it, looking for any special instructions that tell the server to do something, and sends the result of running all of this code back to the browser.

What the Web browser receives is nothing specific to ColdFusion - it is still just text, HTML, JavaScript, and CSS. The difference is that rather than coming from a static "hard-coded" file, this content was generated dynamically. With ColdFusion, developers have the ability to create, manipulate, and output variables; perform conditional logic; redirect the user; retrieve data from a database and loop over that data; send e-mail; manipulate the local file system on the server; and so much more. In order to understand how the ColdFusion Application Server knows what to do when it looks at a ColdFusion page, and to better understand the reasons for creating dynamic pages rather than static HTML pages, let's look at a few typical ColdFusion code examples.

A Few Examples
We learned that ColdFusion looks through the contents of a page to find instructions telling it to do something before returning a page to the browser that requested it. These instructions are written in CFML. As the name implies, CFML is a mark up language. Similar to HTML, CFML is a tag-based language, which tends to make its syntax easy for HTML developers and designers to learn and to use. Unlike the tags in HTML, CFML tags all begin with the letters "CF" - this is how we tell the server what to do. Like HTML (which is also just text) you can write CFML in any text editor, but Dreamweaver MX is the recommended development tool and has many features to make writing ColdFusion applications even faster and easier than it already is.

When the ColdFusion Application Server opens a ColdFusion page (ColdFusion pages typically have a ".cfm" file extension) it parses the contents looking for any tags beginning with "<CF" and does whatever those tags tell the server to do. All other text (text, HTML, JavaScript, CSS, etc.) is ignored and the tags are processed in place. Let's look at an example. We'll begin with the classic "Hello World" application.

In order to tell ColdFusion to say hello, we will create a variable to hold the words "Hello World" and will then tell ColdFusion to output the value of that variable as an HTML header 1. The code is simple enough to look at without ever having seen CFML before (see Image I).


Looking at this code, you see that it is a typical HTML template, with the exception of a few cf tags. The <CFSET> tag is used to create a variable called "msg" with the value "Hello World." In order to display a variable, you first place opening and closing <CFOUTPUT> tags in the page. ColdFusion will resolve any variables contained within the <CFOUTPT> block. You put these variables in the page by surrounding the name of the variable with hash marks (#). Variables may exist in different places in server memory. These places in memory (commonly referred to as "scopes") may be omitted in most cases, but for code readability and performance it's a best practice to prefix variable names with their scope and a dot (to separate the scope name from the variable name). In this example you see that regular (local to the page) variables exist in the "variables" scope.

In this example the HTML header tags are wrapped around the variable within the <CFOUTPUT> block. ColdFusion not only ignores any tags that are not CF tags, but also any text that is not part of an instruction set. So, the <H1> tags are ignored even though they are within the <CFOUTPUT> tags. The header tags could have been moved outside the <CFOUTPUT> block (<H1><CFOUTPUT>#variables.msg#</CFOUTPUT></H1>); the result is the same.

It's also worth noting that ColdFusion doesn't require the tags to be uppercase or lowercase and that variable names aren't case sensitive (#variables.msg# is the same as #Variables.MSG#); that's up to the developer. Also worth noting is that no data type is declared when creating variables. ColdFusion does not care if a variable is a number, string, date, complex variable, etc. - when you write code that expects a certain data type, the server will attempt to cast the variable value to that data type for you (this is known as "loose typing"). The result of browsing to the code above is shown in Image II.


The previous example is fine, but the results could have been achieved just as easily with a static HTML file. Dynamic publishing is very powerful because of its ability to retrieve data from a database or some other source, and dynamically show this data.

Here's an example. You have a public Web site and want to display a catalog of products that you sell. Visitors should also be able to place an order by placing products in a shopping cart. Your company also wants internal applications that allow managers to process the orders, track the current inventory of products, and generate sales reports to show sales per month, YTD sales, most popular products ordered, etc. HTML alone will not allow you to create shopping-cart functionality - but of course you could do that with JavaScript or Flash if you wanted to.

If you create all of these pages with static HTML (and JavaScript or Flash), every time a product is added, removed, or changed you'll have to open each HTML file and modify it. This is a lot of maintenance, and can lead to inconsistencies if product information is not accurately updated in every page that uses it. What makes more sense is to store all of the product catalog information in a database and create ColdFusion pages that retrieve data from the database and use that data to display the catalog. All of the reports would also pull their information from the database, and the current inventory would be stored (and updated when orders are placed) in the database. Now, by adding new products (or modifying or removing current products) to and from the database, all of the Web pages, reports, etc., do not need to be touched. This is because they reflect whatever is in the database in real time. Changes to your data now happen in one place, which keeps things more consistent and requires little or no maintenance of the Web pages and applications that use that data.

Explaining everything there is to know about working with databases is beyond the scope of this article, but like before, the code is very straightforward and easy to read. Image III shows what the code might look like to retrieve all product information from a database and display the catalog as an HTML table. I've added CFML comments (similar to HTML comments but they aren't sent back to the browser) to make the code easier to read.


How CF Works with Other MX Products
Now that we understand what ColdFusion is and the basics of how it works, where does this fit in relation to the other Macromedia MX products? As mentioned earlier, when building a Web application or site, most data should come from a database. ColdFusion's role first and foremost is to retrieve that data. After retrieving the data, ColdFusion manipulates and/or outputs it directly within pages that have the look and feel of your site or app. This look and feel includes graphics and/or menus that might have been created with Fireworks MX or FreeHand. The placement of these graphics within HTML and other text is defined by the page layout (HTML or CSS) as it was defined within Dreamweaver MX. If the site uses Flash, again, graphics might have been created with Fireworks or FreeHand (or the Flash authoring environment), layout of all display was determined within the Flash authoring environment, and data should again be retrieved by Flash from ColdFusion (either using Flash Remoting or Web services).

As you may have guessed, the way the development process typically works is that static versions of HTML pages are created using Fireworks, Dreamweaver, FreeHand, and Flash (if applicable) and then "handed over" to a ColdFusion developer (which certainly might be the same person). A little bit of ColdFusion code is added (using Dreamweaver MX) and the static text is then replaced with dynamic text. The look and feel remains exactly the same as the "static" version, but the actual content is now easily maintainable in one place and is reflective of "real world" data.

Macromedia has been telling us and showing us that the future of Web development is all about user experience. Flash MX and the other Studio MX products allow developers to give these applications an amazing look and feel. Pretty much all of these applications require the ability to allow users to interact with a database, talk with other Web applications, or perform some other sort of complex functionality, and it is here that ColdFusion fills its role in the user experience. CF isn't pretty or glamorous like a Flash animation or a slick Fireworks DHTML menu, but it is an extremely robust and powerful tool that allows developers to create the kind of complex functionality that keeps visitors coming back to your site again and again. To get started with ColdFusion development, I recommend taking Macromedia's Fast Track to ColdFusion course (you can find a classroom near you at http://trainingreg.macromedia.com/tregexternal/). When seeking advice, Macromedia hosts many ColdFusion forums online (http://webforums.macromedia.com/coldfusion/) and the ColdFusion documentation includes a language reference, a "Developing ColdFusion Applications" guide, and a "Getting Started" guide to name a few - all in either HTML or PDF format (www.macromedia.com/support/documentation/en/coldfusion/). There are several popular books on the market and SYS-CON's ColdFusion Developer's Journal (www.sys-con.com/coldfusion/) is well worth the subscription cost as well. Also at SYS-CON's site, you can subscribe to the CFDJ-List, a mailing list that allows you to seek and offer advice to other ColdFusion developers. You can take design only so far before you need to make your Web sites more interactive and functional than traditional tools allow, and ColdFusion makes this complex functionality fast and easy to achieve. There are many resources available to help get you started; I've named just a few.

You can download ColdFusion from Macromedia and use it for free for development and learning. The free license is the "Developer Edition" option when you run the installer, and is fully functional except that the server will respond only to requests from one browser, which is fine for development. Optionally, you can run the free 30-day trial (which is fully functional) and will revert to a developer edition after the 30-day trial expires (all ColdFusion versions share the same installer). Visit www.macromedia.com/go/trycoldfusion/ and download your copy today.

More Stories By Simon Horwith

Simon Horwith is the CIO at AboutWeb, LLC, a Washington, DC based company specializing in staff augmentation, consulting, and training. Simon is a Macromedia Certified Master Instructor and is a member of Team Macromedia. He has been using ColdFusion since version 1.5 and specializes in ColdFusion application architecture, including architecting applications that integrate with Java, Flash, Flex, and a myriad of other technologies. In addition to presenting at CFUGs and conferences around the world, he has also been a contributing author of several books and technical papers.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

@ThingsExpo Stories
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
Recently, WebRTC has a lot of eyes from market. The use cases of WebRTC are expanding - video chat, online education, online health care etc. Not only for human-to-human communication, but also IoT use cases such as machine to human use cases can be seen recently. One of the typical use-case is remote camera monitoring. With WebRTC, people can have interoperability and flexibility for deploying monitoring service. However, the benefit of WebRTC for IoT is not only its convenience and interopera...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Product connectivity goes hand and hand these days with increased use of personal data. New IoT devices are becoming more personalized than ever before. In his session at 22nd Cloud Expo | DXWorld Expo, Nicolas Fierro, CEO of MIMIR Blockchain Solutions, will discuss how in order to protect your data and privacy, IoT applications need to embrace Blockchain technology for a new level of product security never before seen - or needed.
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
"Digital transformation - what we knew about it in the past has been redefined. Automation is going to play such a huge role in that because the culture, the technology, and the business operations are being shifted now," stated Brian Boeggeman, VP of Alliances & Partnerships at Ayehu, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...