Funkiness w/CFC's "OUTPUT" attribute...

Posted by Dan on Nov 14, 2003 @ 10:35 AM

Matt Liotta brought up an interesting point about CFC in CFMX. It's been discovered that the OUTPUT attribute in the <CFFUNCTION> tag, when used to declare a method in a CFC, actually operates as a "tri-state boolean" value—meaning the default value does something different than the behavior if either true or false is specified.

In a nutshell, if you leave the OUTPUT attribute out, the code is processed just like any other CFML is—you need <CFOUTPUT> tags surrounding any variables you want processed and white space is generated as normal. However, if true is passed to the OUTPUT attribute, than all code inside the <CFFUNCTION> tag is implicitly invoked inside a <CFOUTPUT> tag. Lastly, if false is specified as the value for the OUTPUT attribute, than everything inside the <CFFUNCTION> tag is implicitly invoked inside of a <CFSILENT> tag—meaning nothing is outputted.

Here's a some sample code that illustrates the differences. This code is courtesy of Barney Boisvert from the CFCDev Mailing List:

code:
<cffunction name="test">
<cfargument name="name" />
hi #name#
</cffunction>
output: hi #name#


code:
<cffunction name="test" output="True">
<cfargument name="name" />
hi #name#
</cffunction>
output: hi barney


code:
<cffunction name="test" output="False">
<cfargument name="name" />
hi #name#
</cffunction>
output:

I really have to say this isn't the expected behavior of the way you'd expect a boolean attribute to work. Raymond Camden also blogged about this issue and has a nice little dialog going in the comment section.

Categories: HTML/ColdFusion

Comments for this entry have been disabled.