Hello!
Prior to 3.0 m5 I was able to use event.getValue to pull a struct key
using a string for example:
event.getValue("xe.something") //Where xe is a struct with a number of
values in it.
That would get me the value of the string in that struct. In 3.0 m5 it
will throw an error saying that the key doesn't exists, becuase it
only sees the struct "xe" in the collection. Is it possible to have
getValue drill down into the struct and return the value? Here is a
rewritten getValue that will return the string the way it used to.
Thanks!
<cffunction name="getValue" returntype="Any" access="Public" hint="I
Get a value from the request collection." output="false">
<cfargument name="name" type="any" required="true"
hint="Name of the variable to get from the request collection">
<cfargument name="defaultValue" type="any" required="false"
default="NONE" hint="Default value to return if not found.">
<cfargument name="private" type="boolean" required="false"
default="false" hint="Use public or private request collection"/>
<cfscript>
var collection = instance.context;
var split='';
var rtn='';
var i='';
if( arguments.private ){ collection = instance.privateContext; }
if( structKeyExists(collection, arguments.name) ){
return collection[arguments.name];
}
else if(find(".",arguments.name)){
split=listToArray(arguments.name,".");
rtn=collection;
for(i=1; i<=arraylen(split);i++){
if(structkeyexists(rtn,split[i])){
rtn=rtn[split[i]];
}
}
return rtn;
}
else if ( isSimpleValue(arguments.defaultValue) and
arguments.defaultValue eq "NONE" ){
$throw("The variable: #arguments.name# is undefined in the request
collection.",
"Default: #arguments.defaultValue#,
Private:#arguments.private#, Keys
#structKeyList(collection)#","RequestContext.ValueNotFound");
}
else{
return arguments.defaultValue;
}
</cfscript>
</cffunction>