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.

HTML in Application.cfm

The CF_Talk list recently had a discussion about whether it is acceptable to put HTML in Application.cfm. I thought the topic was a very worthy one, but ended up shedding as much heat as light.

I will do my best to shed some light on the topic.

In the short-run, putting HTML in Application.cfm (or including HTML from Application.cfm) can speed up development. If your project ends up changing over time (as most do), however, this can lead to code that is difficult to maintain.

This approach causes problems when different pages have different layouts. For example, a pop-up page would use a different layout than other pages on a site as might the home page.

A common solution is to use a different directory for pages with a different layout so that you could use a different Application.cfm. This makes it slightly more difficult to make common, site-wide logic available to the pages with alternate layouts. The difficulties are more pronounced for a home page with a different layout. Putting every other page in a different directory is impractical.

You could have Application.cfm decide which layout to use based on the file name instead. For example, index.cfm might have a different layout than other files. This is problematic when you or your client want to make a quick copy to test a change.

For example, you might copy index.cfm to index2.cfm at which point the correct layout is no longer being used. Or, perhaps the client might want an alternate home page. Yes, you can always edit Application.cfm with the new file name, but it is counter-intuitive. People expect a copy of a page to look the same as the original.

In fairness, one advantage to including HTML in Application.cfm is that it makes including one page from another very easy (whether or not that is a good idea is another discussion).

On the flip side, it is possible that a client might want part of the layout to change based on which page is being displayed. If you were including the layout code from the page, you could set a variable above the call to the layout to indicate this and perhaps to make some data available for that purpose. If you were including your layout from Application.cfm, that is one more file name check that you have to add to Application.cfm.

These extra bits of code in Application.cfm may not seem like a big deal, but over time they add up to confusing code that is difficult to maintain.

Good luck!

BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.