Welcome!

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.
Enjoy!

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
SYS-CON Events announced today that Massive Networks 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. Massive Networks mission is simple. To help your business operate seamlessly with fast, reliable, and secure internet and network solutions. Improve your customer's experience with outstanding connections to your cloud.
"The Striim platform is a full end-to-end streaming integration and analytics platform that is middleware that covers a lot of different use cases," explained Steve Wilkes, Founder and CTO at Striim, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
SYS-CON Events announced today that Calligo, an innovative cloud service provider offering mid-sized companies the highest levels of data privacy and security, has been named "Bronze Sponsor" of 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. Calligo offers unparalleled application performance guarantees, commercial flexibility and a personalised support service from its globally located cloud plat...
IoT is at the core or many Digital Transformation initiatives with the goal of re-inventing a company's business model. We all agree that collecting relevant IoT data will result in massive amounts of data needing to be stored. However, with the rapid development of IoT devices and ongoing business model transformation, we are not able to predict the volume and growth of IoT data. And with the lack of IoT history, traditional methods of IT and infrastructure planning based on the past do not app...
SYS-CON Events announced today that Datera, that offers a radically new data management architecture, has been named "Exhibitor" of 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. Datera is transforming the traditional datacenter model through modern cloud simplicity. The technology industry is at another major inflection point. The rise of mobile, the Internet of Things, data storage and Big...
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, will examine the regulations and provide insight on how it affects technology, challenges the established rules and will usher in new levels of diligence...
SYS-CON Events announced today that DXWorldExpo has been named “Global Sponsor” of 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. Digital Transformation is the key issue driving the global enterprise IT business. Digital Transformation is most prominent among Global 2000 enterprises and government institutions.
In his session at @ThingsExpo, Sudarshan Krishnamurthi, a Senior Manager, Business Strategy, at Cisco Systems, discussed how IT and operational technology (OT) work together, as opposed to being in separate siloes as once was traditional. Attendees learned how to fully leverage the power of IoT in their organization by bringing the two sides together and bridging the communication gap. He also looked at what good leadership must entail in order to accomplish this, and how IT managers can be the ...
DX World EXPO, LLC., a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
Everything run by electricity will eventually be connected to the Internet. Get ahead of the Internet of Things revolution and join Akvelon expert and IoT industry leader, Sergey Grebnov, in his session at @ThingsExpo, for an educational dive into the world of managing your home, workplace and all the devices they contain with the power of machine-based AI and intelligent Bot services for a completely streamlined experience.
In the enterprise today, connected IoT devices are everywhere – both inside and outside corporate environments. The need to identify, manage, control and secure a quickly growing web of connections and outside devices is making the already challenging task of security even more important, and onerous. In his session at @ThingsExpo, Rich Boyer, CISO and Chief Architect for Security at NTT i3, discussed new ways of thinking and the approaches needed to address the emerging challenges of security i...
While the focus and objectives of IoT initiatives are many and diverse, they all share a few common attributes, and one of those is the network. Commonly, that network includes the Internet, over which there isn't any real control for performance and availability. Or is there? The current state of the art for Big Data analytics, as applied to network telemetry, offers new opportunities for improving and assuring operational integrity. In his session at @ThingsExpo, Jim Frey, Vice President of S...
"DX encompasses the continuing technology revolution, and is addressing society's most important issues throughout the entire $78 trillion 21st-century global economy," said Roger Strukhoff, Conference Chair. "DX World Expo has organized these issues along 10 tracks with more than 150 of the world's top speakers coming to Istanbul to help change the world."
"We provide IoT solutions. We provide the most compatible solutions for many applications. Our solutions are industry agnostic and also protocol agnostic," explained Richard Han, Head of Sales and Marketing and Engineering at Systena America, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We are focused on SAP running in the clouds, to make this super easy because we believe in the tremendous value of those powerful worlds - SAP and the cloud," explained Frank Stienhans, CTO of Ocean9, Inc., in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
"We've been engaging with a lot of customers including Panasonic, we've been involved with Cisco and now we're working with the U.S. government - the Department of Homeland Security," explained Peter Jung, Chief Product Officer at Pulzze Systems, in this SYS-CON.tv interview at @ThingsExpo, held June 6-8, 2017, at the Javits Center in New York City, NY.
The financial services market is one of the most data-driven industries in the world, yet it’s bogged down by legacy CPU technologies that simply can’t keep up with the task of querying and visualizing billions of records. In his session at 20th Cloud Expo, Karthik Lalithraj, a Principal Solutions Architect at Kinetica, discussed how the advent of advanced in-database analytics on the GPU makes it possible to run sophisticated data science workloads on the same database that is housing the rich...
Internet of @ThingsExpo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, is co-located with 21st Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The Internet of Things (IoT) is the most profound change in personal and enterprise IT since the creation of the Worldwide Web more than 20 years ago. All major researchers estimate there will be tens of billions devic...
What sort of WebRTC based applications can we expect to see over the next year and beyond? One way to predict development trends is to see what sorts of applications startups are building. In his session at @ThingsExpo, Arin Sime, founder of WebRTC.ventures, discussed the current and likely future trends in WebRTC application development based on real requests for custom applications from real customers, as well as other public sources of information.
"MobiDev is a Ukraine-based software development company. We do mobile development, and we're specialists in that. But we do full stack software development for entrepreneurs, for emerging companies, and for enterprise ventures," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.