Check out our Angular Book Series.

Learning Cairngorm (Part 2)

In my previous post I talked about some of my experiences while trying to learn Cairngorm. This post extends on those experiences, as I continue to read Steve Webster's series of articles on the framework.

Getting the Cairngorm Store to work

Part three of Steven's series finally starts to get some meat. He goes through the example of how to use the Model Locator pattern within the Cairngorm store application. The Cairngorm store is a modification of The Flex store. The Flex store was designed to showcase features of Flex. The Cairngorm Store is just The Flex Store rebuilt to demonstrate how to build apps using Cairngorm. This article was a bit lost on me without reviewing the code. I think it's time to download the Cairngorm 2.1 Store and see if I can get it running.

I downloaded the store zip file, create a new Flex Builder project and pointed it to that directory. 8 errors exist right off the bat. After a look at a few of the errors, it seems the store download doesn't contain the Cairngorm framework. So, I grab the framework and unzip it into the same directory. The framework tries to overwrite some of my eclipse property files. I declined that.

Seven errors went away, a new one came up, and one stayed constant. This is progress.

com.adobe.cairngorm.IServiceLocator.as throws an error on line 92. 1046: Type was not found or was not a compile tome constant: DataService. A function's return type is set to DataService. mx.data.DataService is properly imported in this component. I am not the only one with these errors. I discovered the solution on Flex Coders. You must add the cairngorm.swc file to the class path.

I tried that and had no more errors, the Cairngorm store is able to compile and run. Another hurdle down. Unfortunately, we aren't out of the woods yet.

So, where are my Products?

When loading the app, the products are not found. I figure there is a path error somewhere. How do I debug this?

I started with the main.mxml. OnCreationComplete, a Cairngorm event is fired named "EVENT_GET_PRODUCTS"). I forget how, but I ended up in com/adobe/cairngorm/samples/control/shopcontroller.as. I think this defines what happens when events get fired. When the EVENT_GET_PRODUCTS is fired the GetPRoductsCommand is ... Well, I dunno, but I opened that file next. The execute method triggers a getProducts method in ProductDelegate. ProductDelegate calls "GetRemoteObject" for productService.

(Note: In Flex Builder a control click will open the source code on the object if it is available. I used this a lot to try to figure out what was being called and where )

I'm guessing that at this point that my remoteObject is incorrect and the productService is somehow pointed at the wrong place. I had Services.mxml opened (but I'm not sure why) and I think I found the problem there. All services are defined here as RemoteObjects. The RemoteObjects specify a destination. The RemoteObject class will only work with Flex Data Services. The destination attribute points to an entry in the services-config.xml.

I don't have Flex Data Services installed. This store is in serious need of some documentation, or at least a readme file. I'm thinking I can replace the RemoteObject with some other form of data retrieval, but, then I realize I don't have data anywhere. There is some shipping and state information in XML documents, but no products.

What Next?

Now I start doing some digging into other directories. I discover that the Java code is included in the application. Poking through, I discovered that the Java Code is not accessing a database or external datasource. It's just manually populating the Value Objects and sending them back.

I bet the backend could be rewritten in ColdFusion. And that is my plan for part 3.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Fred Leefarr's Gravatar Thanks for writing this up. I ran into the "Type was not found or was not a compile time constant: DataService" error when trying to build a Cairngorm app using flash develop and the flex 2 sdk. I noticed (by accident!) that Cairngorm 2.2 is now out, and comes in two flavors - standard and enterprise. Dependency on the flex data services have now been moved into the enterprise version.
# Posted By Fred Leefarr | 4/28/07 1:25 PM
Erin Isvik's Gravatar I too am working with the Cairngorm Store example and ran into the same problem you mentioned because we do not use the Flex Data Services. One solution I found was on Chen Bekor's blog, http://ntier.wordpress.com/2006/12/02/modified-cai..., and he is using the MockObjects to populate the product catalog. I decided to see if I could come up with another solution and chose to create an xml file with the product information in it and use an HTTPService to load the data.
# Posted By Erin Isvik | 4/30/07 2:46 PM
Jeffry Houser's Gravatar Fred,

Glad to help.

Erin,

As far as generic examples go, using some form of XML is much better than tying into CF or FDS. I bet reworking the store for that will be great experience in both Flex and Cairgorm. You could look into u sing the mx:model tag to make it work w/o using HTTPServices if you were feeling really adventurous.

Thanks both for reading!
# Posted By Jeffry Houser | 4/30/07 10:39 PM
All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.