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
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...
BnkToTheFuture.com is the largest online investment platform for investing in FinTech, Bitcoin and Blockchain companies. We believe the future of finance looks very different from the past and we aim to invest and provide trading opportunities for qualifying investors that want to build a portfolio in the sector in compliance with international financial regulations.
Imagine if you will, a retail floor so densely packed with sensors that they can pick up the movements of insects scurrying across a store aisle. Or a component of a piece of factory equipment so well-instrumented that its digital twin provides resolution down to the micrometer.
In his keynote at 18th Cloud Expo, Andrew Keys, Co-Founder of ConsenSys Enterprise, provided an overview of the evolution of the Internet and the Database and the future of their combination – the Blockchain. Andrew Keys is Co-Founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settle...
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.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
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...
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...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
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...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
When shopping for a new data processing platform for IoT solutions, many development teams want to be able to test-drive options before making a choice. Yet when evaluating an IoT solution, it’s simply not feasible to do so at scale with physical devices. Building a sensor simulator is the next best choice; however, generating a realistic simulation at very high TPS with ease of configurability is a formidable challenge. When dealing with multiple application or transport protocols, you would be...
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 ...
We are given a desktop platform with Java 8 or Java 9 installed and seek to find a way to deploy high-performance Java applications that use Java 3D and/or Jogl without having to run an installer. We are subject to the constraint that the applications be signed and deployed so that they can be run in a trusted environment (i.e., outside of the sandbox). Further, we seek to do this in a way that does not depend on bundling a JRE with our applications, as this makes downloads and installations rat...
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
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.
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
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 ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
The IoT Will Grow: In what might be the most obvious prediction of the decade, the IoT will continue to expand next year, with more and more devices coming online every single day. What isn’t so obvious about this prediction: where that growth will occur. The retail, healthcare, and industrial/supply chain industries will likely see the greatest growth. Forrester Research has predicted the IoT will become “the backbone” of customer value as it continues to grow. It is no surprise that retail is ...