No idea is dumb... Actually, I never really thought about this because I
don't usually pass structs around because I either use call-method
(1.8+) or pass in individual arguments.  That being said... it is an
interesting idea.

It's bit close to our Utils copyToScope() which offers a bit more
functionality.

<cfset var argsToPass = StructNew() />

<cfset
getUtils().copyToScope("${event.firstName:''},${levent.lastName},squirrelZipper=${event.oakTree},someProperty=${properties.someValue}",
argsToPass) />

CopyToScope() offers a couple additional features:

* Assign results to a different key - squirrelZipper=${event.oakTree}
* Allowing you to set defaults - ${event.firstName:''} sets a default
value of "" (zero-length string)
* Assignments from properties in addition to event-args
* Deep diving via ${event.person.firstName} calls getFirstName() from
the person bean

Does that work for you?  I know it's slightly more typing due to the M2
EL syntax.  All the things the CopyToScope() is in the documentation
include more complex cases:

http://trac.mach-ii.com/machii/wiki/UsingCopyToScope

Let's keep discussing it.

.Peter

Joe Bodell said the following on 02/11/2011 02:24 PM:
> All,
>
> Apologies in advance if this has been hashed out and deemed a dumb
> idea. That being said....
>
> machii.framework.event's getArgs() method currently just returns the
> variables.args structure. I've run into more than a few cases where I
> need to grab out several -- but not *all* -- of the event args, but
> end up having to do something like this:
>
> <cfset var argsToPass = structNew()
>
> <cfset argsToPass.firstArg = event.getArg("firstArgName") />
> <cfset argsToPass.secondArg = event.getArg("secondArgName") />
> <cfset argsToPass.thirdArg = event.getArg("thirdArgName") />
> <cfset argsToPass.randomArg = event.getArg("randomArgThing") />
> <cfset argsToPass.SquirrelZipper = event.getArg("OakTree") />
>
> Et cetera. Would it make sense to add an optional argument to the
> getArgs() method to specify a list of arguments to send back, like so:
>     <cffunction name="getArgs" access="public" returntype="struct"
> output="false"
>         hint="Returns all args in this event.">
>         <cfargument name="argList" type="string" required="no"
> default="" />
>        
>         <cfset var returnArgs = structNew() />
>        
>         <cfif arguments.argList EQ "">
>             <cfreturn variables.args />
>         <cfelse>
>             <cfloop list="#arguments.argList#" index="currentArg">
>                 <cfif structKeyExists(variables.args, currentArg)>
>                     <cfset returnArgs[currentArg] =
> variables.args[currentArg] />
>                 <cfelse>
>                     <cfset returnArgs[currentArg] = "" />
>                 </cfif>
>             </cfloop>
>            
>             <cfreturn returnArgs />
>         </cfif>
>     </cffunction>
>
> This way, my original block of code becomes...
>
> <cfset argsToPass = event.getArgs("firstArg,secondArg,thirdArg....") />
>
> and the effect is cleaner-looking code with the same functionality.
>
> Thoughts?
>
> Thanks,
>
> Joe
> -- 
> Come see Team Mach-II at OpenCFSummit - Feb 21-23, Dallas, TX -
> http://www.opencfsummit.org/
>  
> To post to this group, send email to
> [email protected]
> For more options and to unsubscribe, visit this group at
> http://groups.google.com/group/mach-ii-for-coldfusion?hl=en
>  
> SVN: http://svn.mach-ii.com/machii/
> Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

-- 
Come see Team Mach-II at OpenCFSummit - Feb 21-23, Dallas, TX - 
http://www.opencfsummit.org/

To post to this group, send email to [email protected]
For more options and to unsubscribe, visit this group at 
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en

SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

Reply via email to