Thursday, March 25, 2010

Preserving structure sort order in ColdFusion

ColdFusion doesn't preserve the order in which elements were assigned to the structure. If you want to quickly and consistently loop through the items in a structure in the order in which they were assigned, the answer is simply to not use a ColdFusion structure. It's easier (and less stupid) than it sounds.

Instead of this:
<cfset mystruct = StructNew() />

Do this:

<cfset mystruct = createObject("java", "java.util.LinkedHashMap").init() />

A java LinkedHashMap object can be treated exactly the same as a structure created by StructNew(). You can assign values the same way, and you can even loop over it the same way using <cfloop collection="...">. Need to do a StructSort? You can do that, too. The only difference is that cfloop will loop over it in the order in which the elements were assigned.

Saturday, February 06, 2010

See my goofy mug on TV!

If you are curious about my non-technical side, catch me on television tomorrow on DIY Network in an episode of Bathtastic airing at 10 am central/11 am eastern tomorrow, Sunday February 7th as part of DIY's Super Bowl-themed marathon, dubbed the Toilet Bowl. How appropriate. In the episode, we gut my bathroom and turn it into a lavishly swank hot box. Whatever that means. Oh, and it looks like they are going to play up my "lack of skill" when it comes to home remodeling, but considering I remodeled the rest of my house with my own two hands, don't believe everything you see on television. *grin*

Oh, and if you don't have cable or don't get DIY Network, I believe they make the episodes available on the DIY Network website not long after they air.