Tuesday, December 16, 2008

Manipulating CFC Properties through getMetaData

I started toying with the idea of creating a generic utility that would populate a cfc with ‘property’ as in cfproperty data and I have something work now – (this would make the compatibility between flex and the model that much better and more ‘well defined’)


Would this be of benefit to us – i.e. running our model through it which would then create all cfproperty tags for a given object based on the getter methods w/in the object – and determine datatype of string, numeric etc – based on the getter methods data etc –


What sort of things do I have to be careful of ??


Order of the cfproperty tags counts right – and Case sensitivity of the names obviously ??


So the process would either do it alpha – or by order that was returned by getMetaData on the object –

An interesting thing happens however when I’m doing this – I could actually build this into coldspring likely where these properties are autogenerated on the fly and never actually have to exist w/in the cfc (written back to the cfc)


The strange thing happened was this:

Once I do a create object on a cfc – I can dump it and it shows that there are NO properties defined in the meta data – which is good


So I run it through my process where I’m introspecting the cfc and create this ‘properties’ key and append the array to this key.


This works well and now a side by side before and after shows the left object with NO properties and the right with Properties – great.


However the next time I run it – the left side also shows that the object now HAS properties –

This is strange – b/c cfproperty tags don’t actually exist in the cfc – but yet I’m able to fake cf (caching likely) into thinking / assigning these properties to the object.


For Example:

Here my Job Object has NO cfproperty tags:





I’m going to make ColdFusion ‘think’ it has these properties defined on it by manipulating the metadata about the object.

Simple App/UI














There are No properties on the left – On the right below, shows the ‘manipulated’ meta data based on the getter methods in the object.






















Now after I run this again – you see both left and right are identical (cached metadata about the object)






















The left side ‘thinks’ that the object now has these properties available to it- which if called or introspected by Flex, they should be available.

This feels a bit like cheating, but if it doesn’t work – we can always complete this thought by having the process ‘write’ the cfproperty tags back to the object.

Interesting huh?