ColdFusion 9 ORM, Flex 4 and ReferenceError: Error #1065: Variable * is not defined.

I have an annoying personality trait. OK, I am certain that I have more than one, but I am writing today about obsession; I tend to be tenacious when I can't get something to work the way I believe it is supposed to work. It has often been observed that when presented with a software problem that blocks progress, I can become obsessed with resolving it. A few years ago, my mother came to Atlanta to visit me when one such software problem was plaguing me. She could tell how unfocused — on everything but the problem — I had become. After a few hours of "last ditch efforts," I walked away from the problem only to think of the proper solution a few hours later. Luckily, that solution worked and I was able to spend quality time with my mother after a couple of late hours of coding.

Last week, another error presented itself. This time, the problem was a weird error I was getting from Flex while receiving data from ColdFusion. You see, I'd decided to take ColdFusion 9's ORM implementation for a spin and applying what I'd learned to a Flex project I've been working on. The logic for learning ColdFusion's ORM implementation was this: first ColdFusion ORM, then Java ORM/Hibernate, then .NET's Entity Framework which is used a lot at Measured Progress, my new employer. While I don't plan on becoming a full-time ColdFusion developer — or Java or .NET developer, for that matter —it is always good to acquire new skills to use when a good server-side developer is unavailable.

When learning new technologies, there are always risks when things get complicated. I typically always believe I've done something wrong. I obsess over my code to find errors. I double check documentation. I ask my peers. I isolate the problem. I have my code reviewed. I consult with people who have more experience than myself for advice. Typically, the process doesn't move past the "I ask my peers" stage but this time it was different.

The Problem

I was having some strange symptoms using Flex Remoting with ColdFusion. You see, I uninstalled and reinstalled ColdFusion 9 on all of my systems recently. Since then, none of my past Flex projects were working correctly. Errors were appearing where they were not before. Value objects were not being serialized. It wasn't a big deal at the time; not only was I unemployed, but the contract projects I was working on were not using ColdFusion. Recently, when I started working on a ColdFusion/Flex/AIR project, I had focused my efforts on the ColdFusion side of things before beginning work on the Flex code. With the server-code working well, I proceeded to move on to the "easy" part of the code for me: Flex. Unfortunately, that is when I began seeing an error every time I received typed value objects from ColdFusion.

ReferenceError: Error #1065: Variable * is not defined.

That's right: Variable *. I have no idea what that means. No one else I spoke to knew what it meant. I'd bet that only one or two software engineers at Adobe, those who worked on the AMF serializer, would have any idea what that error meant. Needless to say, it was perplexing. After pursuing the matter for hours, whining on Twitter, consulting the CF-ORM-DEV Google Group, and spending time screen sharing on Skype with Eric Fickes I finally decided to consult with the smartest developer that I know: Sim Bateman. He steered me toward the solution. After looking at the results in Charles, we saw that the correct value object was being passed from ColdFusion, but there were some capitalization issues with the class names and properties of these classes. Then, the cause of the problem became clear. Inside the services-config.xml file located inside ColdFusion's wwwroot/WEB-INF/flex folder is a setting that, by default looks like:

<force-cfc-lowercase>true</force-cfc-lowercase>

Ah, the wonders of the ColdFusion. I am pretty sure that I've seen this setting before, but to the life of me I don't believe I've ever needed to change it. With this setting, names Coldfusion Components (CFCs) classes will always be lower-case as will each of the property names inside those classes. So, if I am expecting a value object named User to arrive from ColdFusion, I would not get one with force-cfc-lowercase set to true. You will get an ObjectProxy object.

For typical Actionscript uses, we needed that setting to be:

<force-cfc-lowercase>false</force-cfc-lowercase>

With this change to the services-config.xml file, and subsequent restart of ColdFusion, we can have class names like User and properties like firstName in both our CFCs and Actionscript value objects. While I am fairly certain that most ColdFusion developers out there already knew this, but I wanted to make sure that if the error ever came up for someone else, a Google search might bring this blog post up for them. After making this change, my ORM CFC files came across the wire properly and the error went away. And things are making a lot more sense.

Now I have to make up for the hours of time that were wasted because I forgot about a setting inside a ColdFusion config file.

Comments (0) | Print | Send | del.icio.us | Digg It! | Linking Blogs
2056 Views

Comments