Using CFApplication Inside Of ColdFusion's Application.cfc

Posted May 29, 2007 at 8:43 AM

Tags: ColdFusion

Last week, I gave a Nylon Technology presentation on ColdFusion's Application.cfc component. While giving the presentation, it occurred to me - if Application.cfc is a component just like any other and it really just defines a ColdFusion application, I wonder what would happen if you use ColdFusion's CFApplication tag inside of the Application.cfc. To test this, I set up a very simple Application.cfc:

 Launch code in new window » Download code as text file »

  • <cfcomponent>
  •  
  • <!--- Define application. --->
  • <cfapplication
  • name="CFApp In AppCFC"
  • />
  •  
  • <!--- Define page settings. --->
  • <cfsetting
  • requesttimeout="5"
  • />
  •  
  •  
  • <!---
  • Set an application variable just to be
  • able to echo something out in our CFDump.
  • --->
  • <cfset APPLICATION.CFAppTest = "Interesting" />
  •  
  • </cfcomponent>

The Application.cfc does not contain anything Application.cfc-related; it acts merely as a container for the CFApplication tag. It then uses a standard CFSetting tag and attempts to set an APPLICATION variable that we would echo in a later CFDump.

Then, in index page, all I am doing is CFDumping out the APPLICATION scope:

 Launch code in new window » Download code as text file »

  • <cfdump
  • var="#APPLICATION#"
  • label="CFApplication Test"
  • top="10"
  • />

Running this page throws the following ColdFusion error:

5 >= 0

Not one of ColdFusion's most intuitive errors (something similar to what is seen when using CFQueryParam and cached database structures), but since I was testing something very specific, I knew what caused it. Apparently, you cannot use the ColdFusion's old CFApplication inside of its new Application.cfc component.

Download Code Snippet ZIP File

Post Comment  |  Ask Ben  |  Permalink  |  Print Page





Reader Comments

May 29, 2007 at 8:56 AM // reply »
207 Comments

Which is probably a good thing. ;)

I wonder what happens if you try the same code inside onRequestStart?


Apr 14, 2008 at 4:09 PM // reply »
32 Comments

I was just wondering the same thing so I tried it out. Moving the code to the OnRequestStart function works just fine.


Post Comment  |  Ask Ben

Recent Blog Comments
Nov 22, 2009 at 4:03 AM
jQuery Live() Method And Event Bubbling
C_fieri ... read »
Nov 22, 2009 at 1:56 AM
Learning ColdFusion 9: Using CFQuery In CFScript Can Enable SQL Injection Attacks
Why adobe would give you script equivalent of cfquery is beyond me. I love cfquery tag because it helps me wriite clean sql, and get away from the horrible jdbc queries If I wanted to write javali ... read »
Nov 22, 2009 at 1:45 AM
Streaming Text Using ColdFusion's CFContent Tag And The Variable Attribute
The reason you would want to do this is to stream. Ack json/xml files to ria clients I used thus technique before because putting json in response stream causes debugging info to come thru As well a ... read »
Nov 21, 2009 at 6:47 PM
Hal Helms - Real World Object Oriented Development, Sarasota - Day Five
@charlie griefer, Thank you.. ... read »
Nov 21, 2009 at 5:15 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jose Galdamez, Oh heh yeah I didn't paste the whole code. I should have defined the vars -- my bad. It's fixed thou. Thanks. ... read »
Nov 21, 2009 at 4:49 PM
Styling The ColdFusion 8 WriteToBrowser CFImage Output
Great work yet again Ben! Whilst I didn't use this whole code, I copied some of your regex code for a similar problem with the lack of an alt attribute and unescaped ampersands in CFIMAGE for Railo 3 ... read »
Nov 21, 2009 at 1:13 PM
My First ColdFusion Builder Extension - Encrypting And Decrypting CFM / CFC Files
@Ben, Because I am pedantic, I just want to make sure that everyone knows there is absolutely no encryption going on. There is only encoding and obfuscation. The cfencode tool only obfuscates your C ... read »
Nov 21, 2009 at 12:28 PM
Using ColdFusion Structures To Remove Duplicate List Values
@Jody I can't seem to get your code sample to work. If you are still having problems, try this code out and see if it gets you what you wanted. <!--- Comma delimited list with various duplicates ... read »