ColdFusion Struct Key Names and JS/AS Code

If you use ColdFusion in conjunction with Javascript libraries like ExtJS or Actionscript in Flex or Flash, you are probably used to seeing ColdFusion structures rendered in JS/AS in ALLCAPS, like so:

 

CF code:
<cffunction name="getStruct" access="remote" returntype="struct">
     <cfset mystruct = structnew()/>
     <cfset mystruct.somekey = "somevalue"/>
     <cfreturn mystruct>
</cffunction>

JS result:
// a little pseudo-code
myObject = myService.getStruct();

//alert will show "somevalue"
alert(myObject.SOMEKEY);

By default, ColdFusion translates all struct keys into all caps when it returns a structure via a Web service or AMF call. If you would rather maintain your struct keys in lowercase or camelCase, you can simply use bracket notation instead of dot notation. Personally, I prefer dot notation for convenience, but sometimes I encounter a situation where dot notation would not work because the keyshave spaces or other characters that are illegal in ColdFusion variable names. As we can see with this example, there is another good reason to use bracket notation - case matching between client and server struct keys.

If we change our ColdFusion code to use bracket notation instead of dot notation, we'll get the keys in the case they were written:

CF code:
<cffunction name="getStruct" access="remote" returntype="struct">
     <cfset mystruct = structnew()/>
     <cfset mystruct["someKey"] = "somevalue"/>
     <cfreturn mystruct>
</cffunction>

JS result:
// a little pseudo-code
myObject = myService.getStruct();

//alert will show "somevalue"
alert(myObject.someKey);

 

Introducing the Colony application platform

For the past three years, I have been working on and off on an open-source CFML-based Web application. It  started out as a simple system to store arbitrary structured and unstructured content. I started using it to build more and more complex Web applications, and over time it grew in size and scope. I thought about it for awhile as a content management system, but content management is not what I was aiming for, and not where the platform has really evolved.

After struggling with terminology and purpose, I started thinking about the application as an application platform. What is that? I see it as an implementation of typical application patterns in an integrated package that allows a develoepr to use it in whole or in part, building on the core libraries to create a new solution. 

Once I had the concept clear in my head, I started casting about for a name. After lots of pondering and brainstorming sessions with my colleagues on the CF-Community list, I decided to call the platform Colony. To me, Colony is all about staking out new territory on the Web, building compelling new services, and advancing the state of software.

Colony is also about shared effort and shared reward. To that end, we have just released the platform in alpha under the Apache Software License 2.0. You can get the alpha code and see more about the platform at www.cfcolony.org. The site is graphically challenged and light on content at the moment, but that wil cahnge soon. 

Pulseaudio in Ubuntu 8.10

As of the last couple of releases, popular Linux distro Ubuntu has switched the default sound system for the desktop to the PulsAaudio Sound Server. PulseAudio offers the promise of unified, abstracted access to a computer's sound capabilities, and from that standpoint it is a huge advance over previous solutions. However, the move to PulseAudio has been accompanied by a huge amount of frustration by end users with compatibility problems, crashes, and various conflicts with onboard sound, USB sound, and Adobe Flash and AIR.

Recently, I have experienced a number of these issues myself. (See the related posts for background on my transition to using Ubuntu on my desktop). In November I installed Ubuntu 8.10, and I have had some sound issues ever since. In the last few days, I have spent some time debugging these issues on my system, and I wanted to share my challenges and solutions.

Sound Hardware

I have two separate sound systems - onboard sound on my motherboard and a Bose Companion 3 USB sound system. For this type of configuration, the sound troubleshooting guides I have read recommend deactivating the onboard sound and using USB sound only.I tried that for awhile, but I had an issue. The Bose system has a microphone jack on the volume control, but Ubuntu seems not to see it, it only sees the output device. I need a microphone, so I enabled the onboard sound for that purpose. I have a headset/mic combo attached to the onboard sound system.

Skype

If you work remotely or travel on a regular basis like me, Skpe is a great solution for keeping in touch with people. It offers chat, voice over IP (VOIP) telephony, even video-conferencing. The latest Ubuntu client for Skype works reasonably well, but it tends to seize control of the pulseaudio process and eliminate sound for all other applications. My solution to the problem is to enable onboard sound (by removing any /etc/modprobe.d/blacklist entries and enabling the onboard sound in BIOS), assign USB sound to the first sound source in ALSA:

/etc/modprobe.d/alsa-base

install sound-slot-0 /sbin/modprobe snd_usb_audio

and setting USB sound as the default output sink in pulseaudio:

/etc/pulse/default.pa

 .nofail
set-default-sink alsa_output.usb_device_5a7_1020_noserial_if0_sound_card_0_alsa_playback_0 

 Note that your exact settings will depend on your particular hardware.

After that, in Skype -> Options -> Sounds Devices I set my onboard sound hardware (mine is defined as HDA NVidia (hw:NVidia,0)) as the device for Sound In, Sound Out, and Ringing. The ring will sound in my headset, but that's OK for now. Maybe I'll get one of those Skype phone sets from eBay. This solution works fine and it is the only solution I have found for my system that gets Skype working without taking over the pulseaudio system.

Amarok

I use Amarok for my music library.  I have Amarok configured to use the xine engine in Settings -> configure Amarok -> Engine. This setup works well, though I had to experiment with the settings for PulseAudio (making USB sound the default output sink) to get it to default to USB sound.

Adobe Flash/AIR

I do a lot of development with Adobe tools - ColdFusion and Flex in particular. I use YouTube, etc., so sound support for Flash tends to be important for me. As of right now, I have no sound support in Flash. I have installed the latest Flash 10 plugin (10.0.22.87) from Adobe and followed lots of recommendations from various guides about configuring PulseAudio and troubleshooting Flash sound problems. My best guess right now is that activating the onboard sound has caused a problem with Flash sound support. Since I need Skype more than I need YouTube, I'll be keeping my current configuration for now, but it would be great if Flash could use the PulseAudio system without any problems. 

Even when Flash sound support was working (with a previous Flash plugin), sometimes Flash would have trouble after playing a video, and at that point PulseAudio would lose the USB sound device completely. Killing Firefox (and any AIR applications like Twhirl) and restarting pulseaudio (pulseaudio-k; pulseaudio -D) enabled PulseAudio to find the USB device again.

Miscellaneous Settings

Here are a few things I have set according to the varous guides:

/etc/asound.conf

pcm.pulse {
type pulse
}

ctl.pulse {
type pulse
}

 ~/.asoundrc:

 pcm.!default {
         type asym
         playback.pcm {
                 type plug
                 slave.pcm "hw:0,0"
         }
         capture.pcm {
                 type plug
                 slave.pcm "hw:0,0"
       }
}

I am not 100% sure exactly how all of these settings interact with each other, but it seems for the most part to be a successful setup. Based on the number of reported issues I have seen with Flash sound support, I am going to wait until Ubuntu 9.04 is released in April to see if the problems are resolved.

Ubuntu continues to improve as a desktop OS, but from these experiences, you can see it still has a ways to go to be considered as an easy alternative to OS X or Windows (although the huge number of issues with Vista has certainly provided Ubuntu an opportunity to show its capabilities).

Don't let my experiences discourage you from using Ubuntu. You can run the Ubuntu LiveCD and give Ubuntu a try on your hardware without actually having to wipe out your current OS. If you are seriously considering switching, my advice for now is to either buy a new computer that comes pre-installed with Ubuntu or do your homework and install Ubuntu with supported hardware. 

A Simple Paradigm for RIA Development

Lately at Emergent Path we have been building applications using ColdFusion on the server side and Flex on the front end to create very compelling Rich Internet Apps. I have settled on a standard set of technologies and frameworks that provide a standard way of building web apps, and I wanted to share my thoughts.  I am hardly alone in the direction I am moving. Anecdotally, several people I know have been building applications in a simliar way, and blogs and mailing lists are starting to fill with technical questions around various parts of the solution.

On the client, we use Flex with the Cairngorm framework to build well-organized, maintainable code. Cairngorm has a reputation as being a little heavy, and we have experimented with variaous cusotmizations and simplications of the framework. There are other Flex frameworks out there, but Cairngorm at the moment is the most widely used, so that is our current standard. Flex handles the View and Controller aspects of the application.

On the server, we use ColdFusion 8 (and that's important, upgrade your server!) with Coldspring to handle the Model. Coldspring is robust and scalable and is rapidly becoming my favorite ColdFusion framework. It only handles the model, and it is a complimentary technology to Fusebox, Mach-II, Model-Glue, Coldbox, and in this case, Flex. 

Coldspring supports the Transfer and Reactor ORM frameworks, but to date we have not used them in any development projects. We tend to customize the model code, and ORM for us has no clear advantage over other code generators. We have been using the Illudium Pu-36 Code Generator for our base model generation. It is a fairly limited tool, supporting only 1:1 table-entity mapping, but it is very easy to use and allows for customization of the code templates to suit your own architectural style.

Under this paradigm, our ColdFusion apps end up with an Application.cfc and index.cfm in the root, the coldspring folder, a model folder, a services folder (for remote service proxies), and that's it. The Coldspring.xml config file, and any other folders (such as upload/download directories, db scripts) can be held outside the webroot and accessed through the local file system. Images and CSS elements are held in the Flex source folder and deployed at compile-time to the proper location.

This paradigm offers simplicity, rapid development, scalability, and good code organization for long-term maintainability. I've been thinking about making an acronym for it, but I haven't come up with anything yet. 

BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.