Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion

ColdFusion: Article

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

Solutions for the low-budget developer using HTTP services

Writing ColdFusion to XML Translation
The next step is to write the middle tier, the ColdFusion code that will generate valid XML depending on the data in the database. We're going to want to create five CFM files that will be called in our HTTP service tag. Why five you ask, and not one WSDL. Well, because we're exploring HTTP services. In Flex you won't be able to call on a Web Service inside an HTTP service tag. If you've ever used the Flickr API, you may have noticed that there's one root URL with different sub-URLs that do different things. This is just an example; don't take this URL seriously. With Flickr.com/get.cfm?tag=32, you can clearly see that you can't get anything more from that URL than just the tags. However, Flickr has a whole range of other methods like SOAP and XML-RPC that will let you to do much more. Nevertheless, since we're doing it the HTTP call way, why not take a step-by-step process to write up these CFM files. You can surely apply these techniques in creating a WSDL. We're not going to have registration capabilities in our application, since it's a simple proof-of-concept application, but if you go to Listing 2 you'll see a register.cfm file you can use if you want registration capabilities.

Login.cfm
The next step is to actually let users use the login.cfm file. Since we've already covered the basics of the code in the Register.CFM section, we'll briefly explain what's happing here and you can see the completed code in Listing 2. First, ColdFusion is checking whether the variables defined in the URL exist in the database or not, and if they don't ColdFusion generates an XML message. However, if the username and password exist then ColdFusion generates a successful message and gets all the feeds in the database attached to the username.

RSS Manager Vitals
Since we're building an RSS manager, it would be useless if we just had an RSS reader. So we're going to quickly write two files, which add and read the RSS feed. We have to build a reader in ColdFusion first. Because of Flash Player sandbox security issues, it won't go directly to the site and read it, instead ColdFusion will be the delivery boy that will go and get the feed and pass it locally to the Flash player. Building the Flex Front-End (For the final code see Listing 5)

The foundation of this Flex application relies on the CFM files you created in the previous steps; you'll call these files via HTTP services, and hook up the results to the data grids. Since this explores some topics that were in the intermediate group you should already know how to hook up files and create data grids and so on. I won't walk through the application step-by-step. But I will outline of what's happening in the application.

First, when you load the application in the browser, you'll be prompted with a username and password field. When you insert the right username and password it will make an HTTP call to the login.cfm file with the user and password, and change the state to "feed." If the username and password were successful, you'll be able to add a feed and read it; however, if it wasn't, you'll still be able to go the feed state but won't be able to add or read any feeds.

When you click "add feed," you'll be taken to a new 'add' state that will have a feed name, feed URL field, and save button. Then you'll make a new HTTP call to the file WriteRSS.cfm and add a click handler for the button that will call the WriteRSS.cfm and the login.cfm files so that the data grid refreshes.

Last you'll create your last HTTP call to the ViewRSS.cfm file and you'll add it to the feed URL scope so that it will read the selected item (link) of the data grid that gets all your feeds in the database and then hooks that service to a new data grid. What's going on is that when you click the first data grid, it populates the second data grid with the news from the URL. You'll also create a new text area that will get the description of the selected item in the second data grid, so that when you click on the second data grid it will get the news in the text area.

Well, that's about it for the Flex application. It was simple to build, but with a lot of functionality. As I said before, you can add the register.cfm and make it so that you have to register before you have to use it. You can also add transitions, effects, and cool skins to make your Flex application look pretty. Flex is a technology that is just being discovered, it will soon become the ultimate way to build rich Internet applications and with a growing community it will be as easy to learn as your ABCs.

Links

  • G-uniX Technologies: www.G-uniX.com
  • G-uniX Blog: www.G-uniX.com/blog
  • Eclipse Platform: www.Eclipse.org
  • CfEclipse: www.cfeclipse.org/
  • Adobe Flex Builder: www.Adobe.com/flex
  • 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