Steven Erat's Blog
 
 
Viewing By Entry
 
 

TalkingTree  How do CFCs see arguments passed by argumentcollection?

 

This was a question presented to me earlier today, and while it may be a yawn for many of you, I thought I'd review it here since it stumped me for a little while until I read the docs again.

The problem was that the calling page created a structure and populated a few struct keys with Strings, then passed the whole struct as input to a CFC method with <cfinvoke argumentcollection="#myStruct#" ...> when myStruct was a required input argument of type Struct, but the CFC returned the exception:

The parameter MYSTRUCT to function handleArgCollection is required but was not passed in.

The example presented to me was slightly deeper where CFC1 method1 was invoking CFC2 method1 and passing it the struct as an argumentcollection.

When listening to people explain problems its easy to supplant what you know about a subject with the suggestion of what is being described to you. The power of suggestion I suppose. So that is how I got sidetracked into building a reproducible case for this because for a while I forgot what I knew and assumed that what I was being shown was the right way to do it.

The problem was caused by identifying the Struct as a required input parameter of type Struct in method's cfargument tag and then referencing arguments.myStruct.keyname. The proper way to do this instead is to list the keynames as required arguments of type String (or whatever the keys contain), and then reference them by arguments.keyname.

To me, this issue exemplifies why I prefer to receive the shortest possible description of a problem with the smallest example code instead of listening to a lengthy description with extraneous code. Sometimes the power of suggestion just takes over your previous inclinations and pushes the solution that much further away. What I should have done first is to confirm what the docs say about how argumentcollections are handled:

When you pass an argumentCollection structure, each structure key is the name of a parameter inside the structure.

The example CFC invocation of Comp2 from the CFC Comp1 is:

<cfset var result = "">
<cfset var myStruct = structNew()>
<cfset myStruct["a"] = 1>
<cfset myStruct["b"] = 2>
<cfset myStruct["c"] = 3>

<cfinvoke      
argumentcollection="#myStruct#"
component="Comp2"
method="handleArgCollection"
returnvariable="result" />

The CFC method argument declaration and usage that produced the error is:

<cfargument name="myStruct" required="yes" type="struct">
      <cfset msg = arguments.myStruct["a"] & arguments.myStruct["b"] & arguments.myStruct["c"]>

And the corrected usage is:

<cfargument name="a" required="yes" type="string">
<cfargument name="b" required="yes" type="string">
<cfargument name="c" required="yes" type="string">
      <cfset msg = arguments["a"] & arguments["b"] & arguments["c"]>

 


Comments

Good post. While I knew this already, I see almost no one use this feature (or attributeCollection in custom tags), so I'm happy you are reminding people about it.


 

 

Calendar

 
Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Search This Site

 
This is an exact search only

About This Site

 
I live west of Boston and work for Adobe with ColdFusion and Flex, and specialize in Linux. I'm also interested in travel and science, and I'm studyng photography at CDIA. Curious about my banner image?

More about me

Recent Entries

 
Creative Economy Director - M..
2008 Codie Awards: Adobe Cold..

Recent Comments

 
Posted By Samuel Williams:
I believe we're experiencing this problem (or something very similar) in CF 7. When I add references to a keystore in jvm.config, the truststore fail ...

Posted By chris hough:
thank you for posting this solution to this bug, I just used successfully to fix this issue in cf8

Posted By Steven Erat:
I've been using Maxtor for a couple years now and have had no problems (other than the time I dropped one that was plugged in which caused unrepairabl ...

recently played

 
Rick Smolan - America at Home
by Dr. Moira Gunn
on IT Conversations
IT Conversations, Dr. Moira Gunn

now playing, a plug-in for itunes

Categories

 
RSS Adobe (29)
RSS Bicycling (9)
RSS Blogging (37)
RSS Books (13)
RSS Breeze (12)
RSS CFMX Podcasts (10)
RSS ColdFusion (417)
RSS Computer Technology (49)
RSS Events (25)
RSS Flash (3)
RSS Flex (17)
RSS Gadgets (10)
RSS HiTech Industry (15)
RSS Java (25)
RSS Learning (54)
RSS Linux (70)
RSS Mac OS X (21)
RSS Macromedia (28)
RSS Meetup (34)
RSS New England (59)
RSS Odds & Ends (25)
RSS Outdoors (32)
RSS Personal (26)
RSS Photography (104)
RSS Photoshop (28)
RSS Podcasts (18)
RSS Rants (18)
RSS Restaurants (8)
RSS Science (34)
RSS Spain (16)
RSS Travel (42)
RSS Video (20)
RSS Webcam (3)
RSS Writing (10)

Blogs I Read

 
Scrum Sucks
Ben Forta
Ray Camden
Kinky Solutions
Matt Woodward
Red Hat Blogs
O'Reilly Digital Media
O'Reilly Radar
John Nack
The Strobist
Scott Kelby
Matt Kloskowski
Stephen Shankland
Digital Photography School
Engadget
Science Blog
3rd House Journal

RSS

 


Add to Google
Add to My Yahoo!

Aggregated By

 


Consumed By Feed-Squirrel.com
Aggregated by ColdFusionBlogger.org

Credits and Stuff

 
BlogCFC - Free ColdFusion Powered Blog Software
CJM Group - ColdFusion Website Hosting


 
 
blog | photos | flickr | referers | webcam | stats | about | contact
 
Copyright © 2008 Steven Erat. All rights reserved.
This is a personal weblog. The opinions expressed here represent my own and not those of my employer