ColdFusion Method Attribute Output=True Does Not Jive With EnableCFOutputOnly

Posted February 20, 2007 at 12:47 PM by Ben Nadel

Tags: ColdFusion

I was talking to Michael Dinowitz last night at the NY-CFUG about the ColdFusion CFSetting attribute, EnableCFOutputOnly. We had just seen an example where a ColdFusion user defined function had its "Output" attribute set to "True" and also had CFOutput tags inside the method body as well. Michael argued that this was redundant as the Output attribute did just that - created a CFOutput-like environment. I agreed that this was true, except for when EnableCFOutputOnly was turned on; in that case, the additional CFOutput was required. I think he disagreed, but I don't quite remember. Regardless, here is the test:

  • <!---
  • Set it up so that only output inside of
  • CFOutput will be rendered.
  • --->
  • <cfsetting
  • enablecfoutputonly="true"
  • />
  •  
  •  
  • <!---
  • Define a ColdFusion method. The output attribute is set
  • to true. This should create a CFOutput-like environment
  • for the method body.
  • --->
  • <cffunction
  • name="OutputValue"
  • access="public"
  • returntype="void"
  • output="true"
  • hint="Outputs the given value.">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="Value" type="string" required="true" />
  •  
  • <!--- Output value. --->
  • <cfoutput>#ARGUMENTS.Value#</cfoutput>
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  •  
  • <!--- Test what gets output. --->
  • <cfoutput>
  • This value should be output:
  • </cfoutput>
  •  
  • <!--- Call a method that has OUTPUT=TRUE set. --->
  • <cfset OutputValue(
  • "Stars When you shine, you know how I feel."
  • ) />

As you can see, part of the content is wrapped in a CFOutput tags and part of it relies on the OUTPUT=TRUE attribute of the ColdFusion user defined method. Running the above code gives us:

This value should be output:

Now, if we go in and update the UDF to have a CFOutput tag:

  • <!--- Output value. --->
  • <cfoutput>#ARGUMENTS.Value#</cfoutput>

... and then run the code again, we get:

This value should be output: Stars When you shine, you know how I feel.

So, you can see here that OUTPUT=TRUE in a method has no effect if CFSetting has EnableCFOutputOnly enabled.

But, that's settings and methods that are in the same variables scope, if you will (not sure how else to say that). One of the other things that I discussed very briefly with Michael was the affect of CFSetting on a separate object such as a CFC or a custom tag. Again, I am not sure we agreed on this.

To test, I created a CFC for testing output both to the SAME output buffer and also to a completely separate file buffer:

  • <cfcomponent
  • output="true">
  •  
  • <cffunction
  • name="TestOutput"
  • access="public"
  • returntype="void"
  • output="true"
  • hint="Outputs the given value.">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="Value" type="string" required="true" />
  •  
  • <!--- Output value. --->
  • #ARGUMENTS.Value#
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  •  
  • <cffunction
  • name="TestFileOutput"
  • access="public"
  • returntype="void"
  • output="true"
  • hint="Outputs the given value to a file.">
  •  
  • <!--- Define arguments. --->
  • <cfargument name="Value" type="string" required="true" />
  •  
  • <cfset var strOutput = "" />
  •  
  • <cfsavecontent variable="strOutput">
  • <cfoutput>Value:</cfoutput>
  • #ARGUMENTS.Value#
  • </cfsavecontent>
  •  
  • <!--- Output value to file. --->
  • <cffile
  • action="APPEND"
  • file="#ExpandPath( './cfoutput_test.txt' )#"
  • output="#strOutput#"
  • />
  •  
  • <!--- Return out. --->
  • <cfreturn />
  • </cffunction>
  •  
  • </cfcomponent>

Now, let's tweak the original code to use the Test ColdFusion component:

  • <!--- Create an instance of the Test CFC. --->
  • <cfset objTest = CreateObject( "component", "Test" ) />
  •  
  • <!--- Output the intro. --->
  • <cfoutput>
  • This value should be output:
  • </cfoutput>
  •  
  •  
  • <!--- Try outputting value from the CFC. --->
  • <cfset objTest.TestOutput(
  • "Stars When you shine, you know how I feel."
  • ) />
  •  
  • <!--- Try outputting value to file (from the CFC). --->
  • <cfset objTest.TestFileOutput(
  • "Stars When you shine, you know how I feel."
  • ) />

Running this, again we get:

This value should be output:

But, now, if we check the "cfoutput_test.txt", we get this:

Value:

As you can see, with the CFSetting EnableCFOutputOnly attribute enabled, it affects not only things in the same scope and output buffer, but ALL calls made during that request (after the CFSetting tag of course) including buffers built for CFFile usage. Very interesting. This goes to show you that you should be very careful when using EnableCFOutputOnly as its effects are quite far reaching.



Reader Comments

Feb 20, 2007 at 3:35 PM // reply »
26 Comments

What I had said was that UDFs and CFCs run in their own 'space' and what happens within them should not be effected by a CFSETTING. On the other hand, the content outputted to the page would be affected. I've run some tests that got very different results than what you have.

Oh, and the term argued seems to be a loaded one. We whispered it back and forth during a presentation. :)


Feb 20, 2007 at 3:40 PM // reply »
11,246 Comments

Shhhhhh! You don't want people knowing we weren't paying attention :)

Yes, I did not mean "arguing". Just that we were discussing (over the span of about 7 seconds). Personally, I hope that your opinion is more correct as it seems silly to me that a CFSetting in one file should affect the CFFile action of component... something ain't right about that (though I guess you could argue both ways).


Feb 20, 2007 at 3:50 PM // reply »
26 Comments

weren't paying attention? I think the two of us were responsible for at least half of the 'write it down to ask later' questions. Some of our questions will either go to BD docs or make them rewrite parts of their server core. :)

I'm still seeing strange results from my tests that still say that UDFs are not effected by CFSETTING. On the other hand, assigning a UDF result to a variable on a page with a CFSETTING seems to be effected.

Really strange.


Feb 20, 2007 at 3:56 PM // reply »
11,246 Comments

Note: Both Michael and I seemed to be on the right track - depending on variable usage. Michael is logging this inconsistent behavior as a bug.


May 24, 2012 at 1:47 PM // reply »
1 Comments

The word 'jive' in your heading is, I think, in error. The word you wanted was 'gibe'. Of course, its five years later now, but what is that when your words will be immortal?


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
May 25, 2013 at 10:08 AM
Using "//" And ".//" Expressions In XPath XML Search Directives In ColdFusion
@Ben, my question is that i want the current node with its tag and its parent node. i just want only that data. So, give me the solution for that. and remember solution is working on " xpath 1.0 ... read »
May 25, 2013 at 10:01 AM
Using "//" And ".//" Expressions In XPath XML Search Directives In ColdFusion
hey ben, i want get my current node tag and also want the root node tag withing. So, how can i fix it.. ! ... read »
May 24, 2013 at 5:39 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Adam Oops! My mistake! I hadn't gotten that far in my testing - I'm still baby stepping my way through the process. ... read »
May 24, 2013 at 5:13 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
Hi Jason, Thanks for checking up on that, but I still stand firm on my position. :) There are actually two listLast()'s in use, and you're right that the one using a space as a delimiter is fine. ... read »
May 24, 2013 at 4:45 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Ben I have been lurking your site for quite some time, and haven't stepped up to comment until today. Thanks for all the great info - keep it up! @Adam I believe you are mistaken... as the commen ... read »
May 24, 2013 at 11:21 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, Ha ha, let's us never speak of justifying "##" notation again :P ... read »
May 24, 2013 at 11:18 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Ah, so it was indeed how I vaguely remembered it to be: A direct assignment value = users.id[ i ] causes value to retain the sticky datatype of the query column. Although unnecessary in ... read »
May 24, 2013 at 9:11 AM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Brandon, Hi, No, I haven't been able to do that. I have just kept it as it is. ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools