Create A Mini Multiple RSS Reader With Flex 2.0 and ColdFusion 7
Introduction
I recently needed to create a small widget that would allow users to select one of 3 RSS feeds, view the titles and descriptions in each feed, and be able to click on a button to go to the link for an item. Since I had previously read Sas Jacobs excellent article about using Flex and ActionScript 3 to load an RSS feed (available on DMX Zone) and had just completed reading Professional Adobe Flex 2 (Wrox), I understood the basics of using an RSS XML file in Flex. What I wasn't clear on was how to allow the user to select 1 of 3 different RSS feeds. However, the combination of ActionScript 3 and Flex's LinkBar control made it easy.
Example - Flex Widget
You can view an example of the multi RSS Reader Flex widget and right click on the widget to view the source code. Please keep in mind that I had to make this reader small as it will go on a web page that is already bit crowded. The code is extensively commented to assist in understanding what's happening.
Backend
Because of Flash security restrictions, I needed to use a ColdFusion CFC to pull in the RSS XML file. You can view that CFC as part of the source code. You just send the CFC the URL of the RSS XML file and ColdFusion gets it and returns the XML to the Flex application.
User Interface in Flex
Once the XML is returned by the CFC, I create an XMLList object that holds all the item nodes in the XML. Each item node has a title, link, and description child node. I use the title nodes to populate a mx:List control. The user can click on a button to load the link for that title in a new browser window. I also display the description below the mx:List control.
I use a mx:LinkBar control to display the three RSS feed choices. When the application first loads, I create an ArrayCollection that is the data provider for the LinkBar. The ArrayCollection stores generic objects and each object has a label, feed, and newsTitle property. The label property stores the text that is displayed in the LinkBar and the feed property is the RSS feed URL. When the user clicks on one of the LinkBar items, the feed for that RSS is sent to the CFC. When the XML for that feed is returned to the Flex application, the titles in that XML are put into mx:List control.
Important Notes
There is no error handling in this version. So if the RSS XML cannot be loaded by the CFC and returned to Flex, only an Alert box displays. I'll work on adding robust error handling in the next version. Another change is to remove the hard-coded RSS feed information from within the MXML and put it into its own XML file that the application can read in and use as the LinkBar's data provider. That will make it easier to swap in new RSS feeds later.
Lastly, the application will only work with RSS XML that follow a specific formatting: channel node - item node and each item node has a title, description, and link child nodes.
Update
A newer version that uses an XML file to determine which RSS feeds to display in the link bar, additional source code commenting and also has improved error handling in the CFC is available here (with source code).
One on this line that says syntax errors:
var request:URLRequest = new URLRequest('feeds.xml');
I have the feed.xml on my server in the right spot.
This line says syntax errors:
navigateToURL(new URLRequest(lstHeadlines.selectedItem.link), '_blank');
What could I be missing?
What am I missing?
Thanks
George
George - can you send me the RSS URL you're trying to use? The error you're getting indicates a problem with the RSS URL.
Thank for getting back to me.
I tried yours with the same result. but I want to use these:
http://www.winespectator.com/RSS/headlines_rss/0,3...
http://www.just-drinks.com/alerts/rssarticle.aspx
I put the above URLs in my feeds.xml file and ran the news reader and everything worked fine.
Below is the feeds.xml I used:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<channel>
<item>
<label>Wine Spectator</label>
<feed>http://www.winespectator.com/RSS/headlines_rss/0,3...;
<newsTitle>Wind Spectator (click on a headline)</newsTitle>
</item>
<item>
<label>Just Drinks</label>
<feed>http://www.just-drinks.com/alerts/rssarticle.aspx&...;
<newsTitle>Just Drinks (click on a headline)</newsTitle>
</item>
</channel>
Thanks for your help, anyother thoughts?
George
trace( xmlResult.toXMLString() );
after this line:
xmlResult = new XML(event.result);
Run the newsreader2 flex app in debug mode in FlexBuilder. You should see the XML returned in the console. If you don't see correct XML then test the RSSFeedService CFC separately with your RSS URLs.
If you don't have the RSSFeedService in the same place then you need to change the <mx:RemoteObject> tag to specify the correct value for the source attribute.
[SWF] /youngsmarket/programs/rss/rss/bin/RSS-debug.swf - 857,535 bytes after decompression
<rss version="2.0">
<channel>
<item>
<title>News Not Available</title>
<link>http://www.winespectator.com/RSS/headlines_rss/0,3...;
<description>Connection Failure: Status code unavailable</description>
</item>
</channel>
</rss>
I do have the RemoteObject pointing to the RSSFeedService, I did rename the mxml to RSS but I dont think that maters. When I try the testrssfeedservice I get pretty much the same as above but in the xml dump format. Im thinking this could be a server setting. my app is here:
http://www.youngsmarket.com/youngsmarket/programs/...
Just a note: I have been working for a year on flex 2 w CF and your site is by far the most informative. Thanks
//Alert.show( ObjectUtil.toString(event.fault) );
in function handleError. Function handleError is called automatically if there is a problem with connecting to or getting back data from the CFC. In the production app the method just shows News Not Available.
I'm assuming your web host is using CF 7.0.2 or above and that you've successfully used Flex Remote Objects with CFCs before on that web host.
Try testing the RSSFeedService CFC. Put the following in a CFM page in the same directory as the RSSFeedService CFC. Then run the page. When I do this I get a dump of the XML returned by the RSS.
If you don't get the XML dump then change the code in the getRSSXML of the RSSFeedService cfc to output = true and then in the cfcatch block dump the cfcatch variable. That will help find any problems the CFC is having in using cfhttp to pull in the RSS URL.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...;
<html xmlns="http://www.w3.org/1999/xhtml">;
<head>
<InvalidTag http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test RSSFeedService CFC</title>
</head>
<body>
<cfscript>
RSSFeedServiceObj = createObject("component","RSSFeedService");
rssXML = RSSFeedServiceObj.getRSSXML('http://www.winespectator.com/RSS/headlines_rss/0,3...');
</cfscript>
</body>
<cfdump var="#rssXML#">
</html>
I did notice that in the application it runs and says "News Not Available" but if I press "Wine Spectator" and then the Read More button it open up the xml from that site, same if I press "Just Drinks" and press Read More it opens that xml doc.
I just tried the test that you gave me and it dumps the same xml doc as the TestRSSFeedService.cfm
basically it says in the description: Connection Failure: Status code unavailable
Im stumped - server setting?
If you don't get the XML dump then change the code in the getRSSXML of the RSSFeedService cfc to output = true and then in the cfcatch block dump the cfcatch variable. That will help find any problems the CFC is having in using cfhttp to pull in the RSS URL
Connection Failure: Status code unavailable
So that does not help me that much. I can tell the Flex is talking to the RSSFeedService.cfc because I can change the title "News Not Available" and I refresh the app and it changes.
It looks like its all hooked together. If I change the feeds.xml then refresh my app in the browser the titles changes; and the Read More button opens a proper xml page from the site I want but its not the article its the xml doc that I think should be showing up in the headline window. What gives?
George
Try using the cfhttp tag with one of your URLs in a normal CFM page and then dump cfhttp. See if an exception is generated and if you get any information.
I tried dumping the cfhttp and I get the same error:
Connection Failure: Status code unavailable
I tried a few urls but no go.
Sorry for clogging up your blog. Im just wondering, when I go to the sample app and right click view source I see the filles that are used to put it together; when I look at the feed xml a message pops up saying that the page maynot be displayed correctly. Is this what it should look like?
<?xml version="1.0" encoding="ISO-8859-1" ?>
<channel>
<item>
<label>Wine Spectator</label>
<feed>http://www.winespectator.com/RSS/headlines_rss/0,3...;
<newsTitle>Wine Spectator (click on a headline)</newsTitle>
</item>
<item>
<label>Just Drinks</label>
<feed>http://www.just-drinks.com/alerts/rssarticle.aspx&...;
<newsTitle>Just Drinks (click on a headline)</newsTitle>
</item>
</channel>
Im thinking maybe some of the content is blocked and I dont have all the properties of the xml nodes. just a wild thought.
Thanks again
George
If you tested just using cfhttp on a plain CFM page and got the error then the problem is with your server and cfhttp.
Check out this http://kb.adobe.com/selfservice/viewContent.do?ext...
Adobe tech note.
Where is the source code for your app? I can't find it. Thanks!