Couple new functions

2 views
Skip to first unread message

Chuck

unread,
Nov 21, 2009, 1:43:29 PM11/21/09
to model-glue
I added a couple functions to help me understand the state of an
event. I know you could 'dump' the GetAll() but in my case I was
setting a value in a controller like, event.SetValue('loginResult',
event.GetState()._ToString()); to find the value I needed to call to
get the username, since 'username' wasn't returning a value.

To EventContext.cfc

<cffunction name="getState"
access="public"
returnType="ModelGlue.gesture.collections.MapCollection"
output="false"
hint="I get all values by reference.">
<cfreturn variables._state />
</cffunction>

To MapCollection.cfc

<cffunction name="_ToString" access="public" returntype="string"
output="false" hint="I return a string mapping of all the pairs">
<cfargument name="struct" type="struct" required="false"
default="#variables.values#" hint="I am the struct to string." />
<cfset var result="{">
<cfset var first = true>
<cfset var i = "">
<cfloop collection="#arguments.struct#" item="i">
<cfif not first><cfset result = result & ", "></cfif>
<cfif IsSimpleValue( arguments.struct[i] )>
<cfset result = result & "[#i#:#arguments.struct[i]#]">
<cfelseif IsStruct( arguments.struct[i] )>
<cfset result = result & "[#i#:" & this._ToString
( arguments.struct[i] ) & "]">
<cfelse>
<cfset result = result & "[#i#:(unknown type)]">
</cfif>
<!---<cfset result = result & "\n">--->
<cfset first = false>
</cfloop>
<cfset result = result & "}">
<cfreturn result>
</cffunction>

I didn't know how to get the MapCollection another way without
creating the additional function in EventContext

Chuck

unread,
Nov 21, 2009, 1:48:19 PM11/21/09
to model-glue
On Init=true, this returns something like,

{[HitCounterDate:2009-11-16 18:03:47.0], [self:index.cfm],
[BTNLOGINFORM:Login], [PASSWORD:smith], [HitCounter:65],
[_CF_CLIENTID:C95FDFB1A65997BFE75C96BF6FAC8CAA], [_CF_NODEBUG:true],
[_CF_NOCACHE:true], [myself:index.cfm?event=], [eventValue:event],
[modelglueReloaded:true], [USERNAME:bob], [title:], [BOOTSTRAP:
{[BOOTSTRAPPER:{[MODELGLUEVERSIONINDICATOR:GESTURE],
[CORECOLDSPRINGPATH:/ModelGlue/gesture/configuration/
ModelGlueConfiguration.xml], [DEFAULTCOLDSPRINGPROPERTIES:{}],
[PARENTBEANFACTORY:], [PRIMARYMODULEPATH:],
[MODELGLUEBEANNAME:modelglue.ModelGlue], [VERSIONINDICATORS:
{[UNITY:UNITY], [GESTURE:GESTURE], [LEGACY:LEGACY]}],
[MODELGLUECONFIGURATIONBEANNAME:modelglue.ModelGlueConfiguration],
[APPLICATIONKEY:_modelglue], [DEFAULTCOLDSPRINGATTRIBUTES:{}],
[COLDSPRINGPATH:C:\Websites\157900dq4\mg/config/ColdSpring.xml.cfm],
[CREATEMODELGLUE:(unknown type)], [CREATEBEANFACTORY:(unknown type)],
[STOREMODELGLUE:(unknown type)]}], [INITIALIZATIONREQUEST:true],
[FRAMEWORK:{[POPULATORS:(unknown type)], [GETCONFIGBEAN:(unknown
type)], [SETIOCADAPTER:(unknown type)], [SETVALIDATIONSERVICE:(unknown
type)], [GETINTERNALBEANFACTORY:(unknown type)], [GETBEAN:(unknown
type)], [SETSTATEPERSISTER:(unknown type)], [INIT:(unknown type)],
[HANDLEREQUEST:(unknown type)], [SETMODELGLUECONFIGURATION:(unknown
type)], [CONFIGURATION:{[EVENTVALUE:event],
[MISSINGEVENT:page.missing],
[DEFAULTSCAFFOLDS:list,edit,view,commit,delete], [SCAFFOLDPATH:config/
scaffolds/Scaffolds.xml.cfm], [GENERATEDVIEWMAPPING:views],
[RELOADPASSWORD:true], [GENERATIONENABLED:false],

etc...

And once init'ed, something more concise,

{[HitCounterDate:2009-11-16 18:03:47.0], [self:index.cfm],
[BTNLOGINFORM:Login], [PASSWORD:smith], [HitCounter:66],
[_CF_CLIENTID:C95FDFB1A65997BFE75C96BF6FAC8CAA], [_CF_NODEBUG:true],
[_CF_NOCACHE:true], [myself:index.cfm?event=], [eventValue:event],
[USERNAME:bob], [title:], [bootstrap:{[INITIALIZATIONREQUEST:false],
[APPKEY:_modelglue], [blockEvent:0]}],
[FIELDNAMES:USERNAME,PASSWORD,BTNLOGINFORM,_CF_NODEBUG,_CF_NOCACHE,_CF_CLIENTID],
[EVENT:user.credentialCheck], [requestFormat:html]}''

Hope you find this useful.

Chuck

unread,
Nov 21, 2009, 2:02:32 PM11/21/09
to model-glue
For arguments sake, these probably don't need to be added. In
hindsight it probably would of made more sense to create a helper
function to string up the struct returned from GetAll() and used it in
the controller. Anyone with an idea of what that would've looked
like?

IE, I know how to create UDF's, but in the controller would it have
been something like, udf._ToString( event.GetAll() ) or
helpers.udf._ToString( event.GetAll() )?

Chuck

unread,
Nov 21, 2009, 4:15:23 PM11/21/09
to model-glue
Ok, I figured it out, it's: helpers.ToString.StructToString
(event.GetAll())

Sorry for the verbose post, unless you find the function helpful.
Reply all
Reply to author
Forward
0 new messages