Shaun Mccran

My digital playground
 
13
O
C
T
2009

ColdFusion structures and case sensitivity examples

Having been using Flex a little more recently I stumbled upon an old issue that I had previously addressed, but it had become second nature, and so I had forgotten about having to learn a workaround in the past. Passing objects from ColdFusion to Flex can be tricky at times, especially as ColdFusion is generally not case sensitive, but Flex is, and this can lead to problems.

I had previously found that how you build your Structure will have an impact the case of the keys. Example one is a Structure built using the traditional dot notation, in a CF 7 and below method:

view plain print about
1<cfscript>
2    newStruct = structNew();
3    newStruct.starter = "Prawn Salad";
4    newStruct.maincourse = "Roast Chicken";
5    newStruct.desert = "Apple Pie";
6
</cfscript>
7
8<cfdump var="#newStruct#" label="Dot notation">

This is the older way of building a Structure, notice how all the keys are uppercase.

The second example is very similar, except that it is using associative array notation, IE brackets to denote the key values, rather than dot notation.

view plain print about
1<cfscript>
2    newStruct = structNew();
3    newStruct["starter"] = "Prawn Salad";
4    newStruct["maincourse"] = "Roast Chicken";
5    newStruct["desert"] = "Apple Pie";
6
</cfscript>
7
8<cfdump var="#newStruct#" label="Struct notation">

Since I originally looked at this ColdFusion 8 (and now 9!) have been released. ColdFusion 8 introduced a new way of creating structures, what casing does this use?

view plain print about
1<cfset newStruct = {
2    starter = "Prawn Salad",
3    maincourse = "Roast Chicken",
4    desert = "Apple Pie"
5} /
>

6
7<cfdump var="#newStruct#" label="CF 8 method">

It also creates an uppercase structure. I haven't really played around with this method enough to see if there is another way of creating a lowercase structure, so for now I'll be sticking to the older associative array method of creating my structures. That way they are easily transferred as a Flex object.

TweetBacks
Comments
todd sharp's Gravatar Have a look here:

http://help.adobe.com/en_US/ColdFusion/9.0/Develop...

Also - FYI - struct["key"] is known as 'associative array' notation.
# Posted By todd sharp | 10/13/09 1:56 PM
Shaun McCran's Gravatar Thanks for the heads up on the terminology, I thought it had a more distinctive naming convention, couldn't for the life of my remember what it was.

In terms of setting the casing at server level (as per your link) I'm much more of a fan of controlling the code base 'in code', and leaving the server config as vanilla as possible, but that is probably because I've mostly been working on shared hosting platforms, and generally don't have access to things like the 'gateway-config.xml'.
# Posted By Shaun McCran | 10/15/09 10:00 AM

This content is purely my opinon, any offence or errors are unintentional, please comment your views appropriately
Site Credits
Aggregated by ColdfusionBloggers.org Powered by Coldfusion

Technology & Science Blogs - BlogCatalog Blog Directory Blog Directory & Search engine