Using argumentCollection with Super

I recently had the need to use argumentcollection with super. Unfortunately, super can't be used with argumentCollection or with named arguments (which would allow me to loop through a structure and set arguments with cfinvokeargument).

Fortunately, I found a solution in the comments of the ColdFusion LiveDocs. As pointed out by "eblackey" (on "Using inheritance and the Super keyword"), if you copy super to this.super, you can then reference methods of this.super using argumentCollection or named arguments.

Adding this line to the pseudo-constructor (anything within <cfcomponent>, but not inside any method - that is not in <cffunction>), will copy super to this.super.
<cfset this.super = super>

Then, when calling a method ("myMethod()" in this example) of super from a method in your component, you can do this to pass all of the arguments of your method to super.myMethod:
<cfset this.super.myMethod(argumentCollection=arguments)>

Note that you won't be able to call private methods from this.super. If you have a constructor that is called when you first instantiate a component (an init method, for example), you might consider copying super there instead of in the psuedo-constructor so that you only make the copy when the component is instantiated and not every time that it is called.

This workaround solved the problem for me. I just started using it, so I will post again if I run into any trouble with it.

Until then, good luck!

UPDATE

This problem exists in ColdFusion MX 6.1, but not 7. See the following link for a related bug in CFMX 7:
http://ray.camdenfamily.com/index.cfm/2005/10/27/CFMX-7-and-Super-Fixes

Thanks to Brian Kotek and Sean Corfield for correcting my oversight.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Super() does work with both argumentCollection and named arguments in CFMX 7.
# Posted By Brian Kotek | 1/9/06 2:57 PM
Brian,

Thanks for the update. I thought I had gotten it to work once - it must have been on the site I have running CFMX 7.

Clearly, I ran into this problem on one of the many sites still running CFMX 6.1 and I should have tested and clarified the distinction.

Thanks for the note!
# Posted By | 1/9/06 3:30 PM
That was true of CFMX 6.1 but super works with argumentCollection and named arguments in CFMX 7 / 7.0.1. Ray blogged this:

http://ray.camdenfamily.com/index.cfm/2005/10/27/C...
# Posted By Sean Corfield | 1/9/06 3:31 PM
Sean,

Yep, Brian already set me straight on this. Sorry for not doing my homework.

For anyone trying to follow the Sean's link to Ray's blog-entry, the software added a space in "CFMX" that shouldn't be there. I added the link to my blog to make life easier.
# Posted By | 1/9/06 3:55 PM
Just so it's clear - while 7 fixes the "super" issue, it doesn't let you do named arguments to a CFC or UDF in a struct. So if you have a UDF in the request scope, you can't do result = request.foo(name="ray"). I logged a bug for this a while ago so hopefully it will get fixed.
# Posted By Raymond Camden | 1/9/06 5:42 PM
I sure hope they get that fixed in "Mystic"!

I am quickly becoming addicted to named arguments.
# Posted By | 1/9/06 6:57 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.