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 SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that N3N will exhibit at SYS-CON's @ThingsExpo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. N3N’s solutions increase the effectiveness of operations and control centers, increase the value of IoT investments, and facilitate real-time operational decision making. N3N enables operations teams with a four dimensional digital “big board” that consolidates real-time live video feeds alongside IoT sensor data a...
SYS-CON Events announced today that NetApp 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. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
There is huge complexity in implementing a successful digital business that requires efficient on-premise and cloud back-end infrastructure, IT and Internet of Things (IoT) data, analytics, Machine Learning, Artificial Intelligence (AI) and Digital Applications. In the data center alone, there are physical and virtual infrastructures, multiple operating systems, multiple applications and new and emerging business and technological paradigms such as cloud computing and XaaS. And then there are pe...
DevOps at Cloud Expo – being held October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real r...
SYS-CON Events announced today that B2Cloud 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. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
SYS-CON Events announced today that Massive Networks, that helps your business operate seamlessly with fast, reliable, and secure internet and network solutions, 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. As a premier telecommunications provider, Massive Networks is headquartered out of Louisville, Colorado. With years of experience under their belt, their team of...
SYS-CON Events announced today that Suzuki Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Suzuki Inc. is a semiconductor-related business, including sales of consuming parts, parts repair, and maintenance for semiconductor manufacturing machines, etc. It is also a health care business providing experimental research for...
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that Keisoku Research Consultant Co. will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Keisoku Research Consultant, Co. offers research and consulting in a wide range of civil engineering-related fields from information construction to preservation of cultural properties. For more information, vi...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...
Elon Musk is among the notable industry figures who worries about the power of AI to destroy rather than help society. Mark Zuckerberg, on the other hand, embraces all that is going on. AI is most powerful when deployed across the vast networks being built for Internets of Things in the manufacturing, transportation and logistics, retail, healthcare, government and other sectors. Is AI transforming IoT for the good or the bad? Do we need to worry about its potential destructive power? Or will we...
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion 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. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...
With major technology companies and startups seriously embracing Cloud strategies, now is the perfect time to attend 21st Cloud Expo October 31 - November 2, 2017, at the Santa Clara Convention Center, CA, and June 12-14, 2018, at the Javits Center in New York City, NY, and learn what is going on, contribute to the discussions, and ensure that your enterprise is on the right path to Digital Transformation.