11 million installations can't be wrong

MySQL Journal

Subscribe to MySQL Journal: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get MySQL Journal: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn


MySQL Journal Authors: Elizabeth White, Jnan Dash, Mehdi Daoudi, Progress Blog, AppDynamics Blog

Related Topics: ColdFusion on Ulitzer, XML Magazine, MySQL Journal

CFDJ: Article

Developing Flex 2 Applications with ColdFusion and XML Without Needing FDS or Mystic

Solutions for the low-budget developer using HTTP services

Flex is one of the greatest technologies around. Combine it with ColdFusion and it just gets better. Adobe has made it possible to use Flex 2 efficiently with ColdFusion and easily get data across the server to a Flex front-end.

It's also released Flex data services that don't need ColdFusion to pass data in and out. However, these technologies might be outside the price range of a small developer or hard to deploy. Take FDS, for example. Of course Adobe has an Express edition, but deploying a good application for all the world to see hosted on your own computer is a hassle, and if you were to go out and look for a host that supports FDS it would cost you about $360 a year. Not a lot for some, but for an individual developer who's already paying for a solid ColdFusion host, it may be too much. Another technology that Adobe introduced was an update to Flash remoting in ColdFusion 7.0.2, yet most hosting providers won't support Flex connectivity on their servers, and again you'd have to buy a VPS, which would cost you $360 a year. Nevertheless, in the world of dynamic technology there are other alternatives. And ColdFusion-generated XML or what some might consider HTTP services is one of them. This is an easy way to get data from your MySQL, Access, and Oracle database and bring it into Flex, read it, update it, and if you want even delete records based on the user level. This article will discuss the basics of using this method, teach you how to build ColdFusion-based XML files, and bring them in and explain how you can use them in your Flex application.

The Background
Using XML as a data delivery source has been around since the dawn of Web 2.0 or before. Almost all Web 2.0 Web sites use XML as a method of delivering news using RSS to their users. Although this is a good way to use XML there are better ways. Instead of transporting news in XML what if you can transport the user data and authentication. Many sites such as Flickr and Blogger have an API that lets you to do this and, in fact, this is a good solution. Rather than getting FDS to retrieve data, we just encapsulate the data in an XML file that in turn is read by Flex and displayed. No Mystic, No FDS, just plain ColdFusion, XML, and Flex.

Why Use This Method over WSDLs, FDS, or Mystic?
There are different ways of getting data from a database and bringing it into your front-end like Web Services (WSDL). However, not a lot of developers who are starting off know how to create a WSDL or they don't have the time to learn how. Using ColdFusion-generated XML basically means creating a query and outputting it through some XML and cfloops. Any ColdFusion developer who is starting off can quickly harness this power and create applications in record time. After all, developing applications that are in demand is a race. Using this method is not restricted to Flex applications, you can create an application in virtually any modern programming language without modifying a single line of back-end ColdFusion code. How? Well, because XML is read, as I said, by any modern programming language, all you have to do is "hook up" the XML to the front-end via an HTTP service call. The application we're going to build in this article makes use of the HTTP service call rather than a Web Service call, and gets all the data back from the server and then the user can manipulate the data.

Another great reason to use this type of programming method is because you can "open" the back-end files or give the links to developers who are masters in their own field who can then develop third-party front-ends using your back-end. This can extend the reach of your site and deliver your data to more people, and will entice developers into creating mashups, where they take your data and using another API (as this is called) mash them up to create one heck of an application. An example would be if your application was a user-based contact manager, and after opening the API to developers, they could take the data and mash it into Google maps, where when you click on the contact it will show where the house is based on the ZIP code.

Time to Build Your Own Application
This isn't your boring old computer science class where all you did was learn theory and learn and learn. As a result instead of telling you more about this type of programming, why not just dive in and learn on the way. The Flex 2 application we're going to build will be an RSS manager, which will have user authentication and a place to keep and read all your favorite RSS feeds. (See Figure 1 for the final application.)

What we're going to create is a bunch of objects that will interact with the Flex application via an HTTP service call and then interact with the database via a cfquery. It will be a learning experience. You'll learn the basics of a Flex application and HTTP services. Also since we're not building a sophisticated application, we're not going to have Flex do the authentication. We'll leave that to ColdFusion simply because it's too hard and will take a lot of time otherwise. What this means is that even if the username/password combination is wrong, Flex will let the user pass through to the next step but there will be no data in the data grid.

It's possible to let Flex do the authentication, but this is just a proof-of-concept application, not a "real-world" one. What I hope is that you learn a little more about this method and then you can build on it however you want.

Getting the Tools
Since this is for the individual developer who wants to make the most out of a small budget, we'll be using tools that are completely free. The first thing you should do is go and download ColdFusion, which you should already have anyway. Next you'll want to downlaod the Eclipse platform along with CFECLIPSE (all the links are at the end of this article), which is a good ColdFusion IDE for coding, not designing. Seeing as how we're going to use ColdFusion just for coding CFECLIPSE is the way to go.

Next you'll want to download the Flex Builder and read up on the compiling instructions since this will be your tool to compile Flex applictions into Swfs that can be run on virtually any server. Yes, there is the free version of Flex 2 called the Flex 2 SDK However, Flex Builder 2 is more enchancing and will make coding a whole lot easier. I recommend that you download Flex Builder 2. In addition you'll also want to download a database technology such as MySQL or Oracle and create a DSN in the ColdFusion Administrator.

Architecting the Database
After that it's good practice to lay out your database first and create all the required tables. This way you can build your Flex 2 application and the ColdFusion code relying on the database rather than making guesses on the tables you'll create. So create a new DSN in the CF Admin named global since all the example code uses this DSN. There will be two tables in this simple application that we're going to create. The first will be a user table that will hold all our user data. It will also add the values Faisal, Faisal (user, pass) and the values Abid, Abid (user, pass). If you want, you can add more, but this application is just a concept application. If you're using MySQL as a database then here's the code:

CREATE TABLE 'CFDJ_users' (
    'member_ID' int(11) NOT NULL auto_increment,
    'Username' varchar(255) NOT NULL,
    'Password' varchar(255) NOT NULL,
    PRIMARY KEY ('member_ID')
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

INSERT INTO 'CFDJ_users' VALUES (1, 'Faisal', 'Faisal');
INSERT INTO 'CFDJ_users' VALUES (2, 'Abid', 'Abid');

Then you'll want to create your RSS table. In this table the user will post a link for an RSS feed and a name to go with it, so the user can come back days later and click on the link and get the feed delivered instantly. You're going to need just four fields for this: an RSS ID field that will be your primary, a username field, an RSS link field, and last an RSS name field. If you did this in MySQL here is the code:

CREATE TABLE 'CFDJ_RSS' (
'Rss_ID' INT NOT NULL AUTO_INCREMENT ,
'Username' VARCHAR( 255 ) NOT NULL ,
'Rss_Name' VARCHAR( 255 ) NOT NULL ,
'Rss_Link' VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( 'Rss_ID' )
);


More Stories By Faisal Abid

Faisal Abid is a third-year student at West Hill CI and loves Flex, ColdFusion, and rich Internet applications. He is also the founder and owner of G-uniX Technologies (www.G-uniX.com), an RIA software development consultancy based in Toronto that specializes in Flex 2 and ColdFusion applications. He has a blog at blog.G-uniX.com that he updates bi-weekly with G-uniX news, Flex tutorials, ColdFusion tutorials, and Spry tutorials.

Comments (1) View Comments

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.


Most Recent Comments
shawn gibson 02/21/07 06:42:51 AM EST

Trying to get this running but I get the following errors in Flex: The reference to entity "Pword" must end with the ';' delimiter.

...any idea what that means? I comment it out, and the same error appears for all the HTTPService lines. Shawn