Using CFContent's Variable Attribute Stops All Further Processing

Posted June 10, 2010 at 8:59 AM by Ben Nadel

Tags: ColdFusion

Yesterday, it was called into question whether or not the use of CFContent's Variable attribute prevented any further processing of the page request. I had suggested it did; but, I wasn't 100% sure. Thinking back, I couldn't remember if I have ever had any code after a CFContent tag that used the Variable attribute (often times, it's the last thing on the page). As such, I thought it'd be easy to whip up a quick test of ColdFusion's expected functionality.

 
 
 
 
 
 
 
 
 
 

The first thing I did was enable session management for the page request. I did this because the ColdFusion livedocs don't expressly refer to page processing - they refer simply to page output:

When you use this attribute [Variable], any other output on the current CFML page is ignored; only the contents of the file are sent to the client.

This is a bit ambiguous as to whether it refers to code execution or just to page output. By enabling session management, we can test session value updates even if the generated output is not being streamed to the client.

Application.cfc

  • <cfcomponent
  • output="false"
  • hint="I define the applications settinsg and event handlers.">
  •  
  • <!--- Define application settings. --->
  • <cfset this.applicationTimeout = createTimeSpan( 0, 0, 5, 0 ) />
  • <cfset this.sessionManagement = true />
  • <cfset this.sessionTimeout = createTimeSpan( 0, 0, 0, 20 ) />
  •  
  • </cfcomponent>

Now that session management is enabled, I created a page that generated page output and updated session values both before and after a CFContent tag:

  • <!---
  • Param the session hit counter to make sure that output
  • is not the only thing that gets altered.
  • --->
  • <cfparam name="session.hitCount" type="numeric" default="0" />
  •  
  • <!---
  • Create a path to the log file so that we can track the
  • parts of the page that actually process.
  • --->
  • <cfset logFilePath = expandPath( "./log.htm" ) />
  •  
  •  
  • <!--- ---------------------------------------------------- --->
  • <!--- ---------------------------------------------------- --->
  •  
  •  
  • <!--- Increment the hit count. --->
  • <cfset session.hitCount++ />
  •  
  • <!--- Log that we made it this far in the page request. --->
  • <cfdump
  • var="Before CFContent (#session.hitCount#)"
  • output="#logFilePath#"
  • />
  •  
  •  
  • <!--- ---------------------------------------------------- --->
  • <!--- ---------------------------------------------------- --->
  •  
  •  
  • <!---
  • Create a binary variable of a text value and stream it
  • to the client using the Variable attribute.
  • --->
  • <cfcontent
  • type="text/plain"
  • variable="#toBinary( toBase64( 'Hey there buddy!' ) )#"
  • />
  •  
  •  
  • <!--- ---------------------------------------------------- --->
  • <!--- ---------------------------------------------------- --->
  •  
  •  
  • <!--- Increment the hit count. --->
  • <cfset session.hitCount++ />
  •  
  • <!--- Log that we made it this far in the page request. --->
  • <cfdump
  • var="After CFContent (#session.hitCount#)"
  • output="#logFilePath#"
  • />

As you can see, I am incrementing and logging the session's hitCount variable both before and after the CFContent tag. In this way, I can see if the session value is updated post-CFContent even if the "output" generated by the CFDump tag is not rendered. After refreshing the page a few times, here's what the log file contains:

Before CFContent (1)
***********************************************************

Before CFContent (2)
***********************************************************

Before CFContent (3)
***********************************************************

Before CFContent (4)
***********************************************************

As you can see, not only does the second CFDump tag never render to the log file, the incrementing session hitCount demonstrates that no code was executed after the CFContent tag.

I had thought that this was the expected CFContent behavior, so it's nice to see ColdFusion work this way. That said, I should remind people that this is only for a very specific use-case of CFContent - the Variable attribute (as well at the File attribute); all other uses of the CFContent tag will simply affect the response headers and the existing output buffer, allowing the rest of the page to process normally.




Reader Comments

Jun 10, 2010 at 5:07 PM // reply »
39 Comments

What about an onRequestEnd.cfm, or OnRequestEnd() in the application.cfc?


Jun 10, 2010 at 5:13 PM // reply »
11,314 Comments

@Tim,

I'm 99% sure that those are no executed either; but I will check and get back to you.


Jun 10, 2010 at 10:29 PM // reply »
2 Comments

Hi Ben,

what happened if any error occured.............


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Jun 19, 2013 at 9:41 AM
Working With Inherited Collections In AngularJS
I actually just ran into this same situation with a demo I was putting together. Your implementation of multi-lvl $scope's > Mine :) ... read »
Jun 19, 2013 at 8:17 AM
My Experience With AngularJS - The Super-heroic JavaScript MVW Framework
@Prateek, to match a word or text you should use .toContain('word') that's a jasmine reference. website is : http://pivotal.github.io/jasmine/ ... read »
Jun 19, 2013 at 8:10 AM
My Experience With AngularJS - The Super-heroic JavaScript MVW Framework
Hi Guys, Actually i am doing e2e test of angular js of my project but i am not getting one thing that is how to press enter key through the test when my form is filled as i am not using a button but ... read »
Jun 18, 2013 at 9:20 PM
Mapping AngularJS Routes Onto URL Parameters And Client-Side Events
I couldn't find examples of passing multiple arguments using the when() routing statement so figured out through trial and error that you can pass multiple arguments using the following format: .whe ... read »
Jun 18, 2013 at 3:39 PM
Experimenting With The Amazon Simple Storage Service (S3) API Using ColdFusion
Hi Ben, THANKS! While not bleeding edge, it is new to me & I like learning new things every day! ... read »
Jun 18, 2013 at 12:30 PM
Disabling Auto-Correct And Auto-Capitalize Features On iPhone Inputs
Also spellcheck="false" should be mentioned as part of html5 specs ... read »
Jun 18, 2013 at 8:40 AM
Using Named Functions Within Self-Executing Function Blocks In Javascript
Hi Ben, you forgot to mention the most important thing for named self-executing functions - they can be referenced by name ONLY inside their execution context (which is parens in this case), it mean ... read »
dee
Jun 18, 2013 at 7:01 AM
My Safari Browser SQLite Database Hello World Example
hai ben, this program is really good i could understand the concept but i dint know how to save it and how to open it as you have done in the video can u give that details pls ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools