<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Using Constants in ColdFusion Components</title>
	<atom:link href="http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/</link>
	<description></description>
	<lastBuildDate>Sun, 08 Jan 2012 15:53:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: Sean</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-137</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Sat, 30 Jan 2010 14:22:35 +0000</pubDate>
		<guid isPermaLink="false">#comment-137</guid>
		<description>Thanks Sean.</description>
		<content:encoded><![CDATA[<p>Thanks Sean.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Corfield</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-136</link>
		<dc:creator>Sean Corfield</dc:creator>
		<pubDate>Sat, 30 Jan 2010 01:54:23 +0000</pubDate>
		<guid isPermaLink="false">#comment-136</guid>
		<description>Whilst I neither condone nor condemn the suggested solution, I wanted to point out that you can short circuit that code quite a bit by using:

for ( key in this ) ...</description>
		<content:encoded><![CDATA[<p>Whilst I neither condone nor condemn the suggested solution, I wanted to point out that you can short circuit that code quite a bit by using:</p>
<p>for ( key in this ) &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-135</link>
		<dc:creator>Sean</dc:creator>
		<pubDate>Tue, 26 Jan 2010 18:32:21 +0000</pubDate>
		<guid isPermaLink="false">#comment-135</guid>
		<description>How about putting all global things in a file that is cfincluded by application.cfc, then in onApplicationStart collect (structure) pointers (to variables or functions) in global (application scope), then in any cfc that requires constants or global functions, refer to the global structure:

See my comments at:
[URL=&quot;http://www.bennadel.com/blog/1776-Creating-Globally-Accessible-User-Defined-Functions-In-ColdFusion-Safer-Version-.htm?&amp;_=0.905060270905669#comments_24513&quot;]Creating Globally Accessible User Defined Functions In ColdFusion (Safer Version)[/URL]

Here was the final solution:

[Put in application.cfc:]

[CODE]

&lt;cffunction name=&quot;onApplicationStart&quot;&gt;

. . . snip . . .

	&lt;cfscript&gt;
	application.globalmethods = structnew();
	keys = structkeylist(this);
	for (i=1; i LTE listlen(keys); i=i+1) {
		key = listgetat(keys,i);
		if (iscustomfunction(this[key]) and left(lcase(key),2) NEQ &quot;on&quot;)
			structinsert(application.globalmethods, key, this[key]);
	}
	application.registerglobalmethods = this.registerglobalmethods;
	&lt;/cfscript&gt;

. . . snip . . .

&lt;/cffunction&gt;

&lt;cfinclude template=&quot;GlobalFunctions.cfm&quot;&gt;

&lt;cffunction name=&quot;registerglobalmethods&quot; output=&quot;no&quot;&gt;
	&lt;cfset StructAppend(variables, application.globalmethods, true)&gt;
&lt;/cffunction&gt;

[/CODE]

Finally, in any cfc that uses a global function, call the register function, then you can use any global function (with no scope prefix):

[CODE]&lt;cfset application.registerglobalmethods();&gt;[/CODE]

Now, you could skip the register function and just use:

[CODE]&lt;cfset StructAppend(variables, application.globalmethods, true)&gt;[/CODE]

when ever a cfc needed to use global functions. But I think this is more readable.</description>
		<content:encoded><![CDATA[<p>How about putting all global things in a file that is cfincluded by application.cfc, then in onApplicationStart collect (structure) pointers (to variables or functions) in global (application scope), then in any cfc that requires constants or global functions, refer to the global structure:</p>
<p>See my comments at:<br />
[URL=&quot;http://www.bennadel.com/blog/1776-Creating-Globally-Accessible-User-Defined-Functions-In-ColdFusion-Safer-Version-.htm?&amp;_=0.905060270905669#comments_24513&quot;]Creating Globally Accessible User Defined Functions In ColdFusion (Safer Version)[/URL]</p>
<p>Here was the final solution:</p>
<p>[Put in application.cfc:]</p>
<p>[CODE]</p>
<p>&lt;cffunction name=&quot;onApplicationStart&quot;&gt;</p>
<p>. . . snip . . .</p>
<p>	&lt;cfscript&gt;<br />
	application.globalmethods = structnew();<br />
	keys = structkeylist(this);<br />
	for (i=1; i LTE listlen(keys); i=i+1) {<br />
		key = listgetat(keys,i);<br />
		if (iscustomfunction(this[key]) and left(lcase(key),2) NEQ &quot;on&quot;)<br />
			structinsert(application.globalmethods, key, this[key]);<br />
	}<br />
	application.registerglobalmethods = this.registerglobalmethods;<br />
	&lt;/cfscript&gt;</p>
<p>. . . snip . . .</p>
<p>&lt;/cffunction&gt;</p>
<p>&lt;cfinclude template=&quot;GlobalFunctions.cfm&quot;&gt;</p>
<p>&lt;cffunction name=&quot;registerglobalmethods&quot; output=&quot;no&quot;&gt;<br />
	&lt;cfset StructAppend(variables, application.globalmethods, true)&gt;<br />
&lt;/cffunction&gt;</p>
<p>[/CODE]</p>
<p>Finally, in any cfc that uses a global function, call the register function, then you can use any global function (with no scope prefix):</p>
<p>[CODE]&lt;cfset application.registerglobalmethods();&gt;[/CODE]</p>
<p>Now, you could skip the register function and just use:</p>
<p>[CODE]&lt;cfset StructAppend(variables, application.globalmethods, true)&gt;[/CODE]</p>
<p>when ever a cfc needed to use global functions. But I think this is more readable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-134</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Sun, 15 Mar 2009 15:09:35 +0000</pubDate>
		<guid isPermaLink="false">#comment-134</guid>
		<description>Hi Christian

Yes, certainly something like ColdSpring may not be for everybody.

However I now quite like the idea of storing constants in a single component that lives in the application scope. As it is only a single component created at application startup, it should have no practical impact on performance.

So in a non-framework or simplified application, you could have:

On application start, create some service that provides access to constants. When this object is created, the constants would be created at the same time.

&lt;cfset application.appService = createObject(&quot;component&quot;,&quot;com.AppService&quot;).init()&gt;

And within the application code, you would make a call such as:

&lt;cfset constants = application.appService.getConstants()&gt;

that would return a struct containing the application constants.</description>
		<content:encoded><![CDATA[<p>Hi Christian</p>
<p>Yes, certainly something like ColdSpring may not be for everybody.</p>
<p>However I now quite like the idea of storing constants in a single component that lives in the application scope. As it is only a single component created at application startup, it should have no practical impact on performance.</p>
<p>So in a non-framework or simplified application, you could have:</p>
<p>On application start, create some service that provides access to constants. When this object is created, the constants would be created at the same time.</p>
<p>&lt;cfset application.appService = createObject(&quot;component&quot;,&quot;com.AppService&quot;).init()&gt;</p>
<p>And within the application code, you would make a call such as:</p>
<p>&lt;cfset constants = application.appService.getConstants()&gt;</p>
<p>that would return a struct containing the application constants.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Küpers</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-133</link>
		<dc:creator>Christian Küpers</dc:creator>
		<pubDate>Sun, 15 Mar 2009 11:41:28 +0000</pubDate>
		<guid isPermaLink="false">#comment-133</guid>
		<description>I think for bigger frameworks the bean instatiation is a good id; for smaller projects we often use our own application and session management, which is instatiating the variables by special cfm-files.

The frameworks often have the problem of performance; a small request will mostly take 500 - 700ms, which is caused by many, many cfc for framework-startup...

the glory way is not always the same... everyone has to check, which kind of app is used in which way.... a cms often has other requirements than a gui of a management interface, used inside a company...</description>
		<content:encoded><![CDATA[<p>I think for bigger frameworks the bean instatiation is a good id; for smaller projects we often use our own application and session management, which is instatiating the variables by special cfm-files.</p>
<p>The frameworks often have the problem of performance; a small request will mostly take 500 &#8211; 700ms, which is caused by many, many cfc for framework-startup&#8230;</p>
<p>the glory way is not always the same&#8230; everyone has to check, which kind of app is used in which way&#8230;. a cms often has other requirements than a gui of a management interface, used inside a company&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-141</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Fri, 09 May 2008 16:59:48 +0000</pubDate>
		<guid isPermaLink="false">#comment-141</guid>
		<description>For reference, the MapFactoryBean is a component available in the CVS version of ColdSpring. Using this component you can create a bean such as:

&lt;bean id=&quot;appConstants&quot; class=&quot;coldspring.beans.factory.config.MapFactoryBean&quot;&gt;
	&lt;property name=&quot;sourceMap&quot;&gt;
		&lt;map&gt;
			&lt;entry key=&quot;product&quot;&gt;
				&lt;map&gt;
					&lt;entry key=&quot;STATUS_ACTIVE&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;
					&lt;entry key=&quot;STATUS_INACTIVE&quot;&gt;&lt;value&gt;2&lt;/value&gt;&lt;/entry&gt;
					&lt;entry key=&quot;STATUS_ARCHIVED&quot;&gt;&lt;value&gt;3&lt;/value&gt;&lt;/entry&gt;
					&lt;entry key=&quot;user&quot;&gt;
						&lt;map&gt;
							&lt;entry key=&quot;STATUS_ARCHIVED&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;
							&lt;entry key=&quot;ADMIN_USER_ID&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;
						&lt;/map&gt;
					&lt;/entry&gt;
				&lt;/map&gt;
			&lt;/entry&gt;
			&lt;entry key=&quot;user&quot;&gt;
				&lt;map&gt;
					&lt;entry key=&quot;STATUS_ARCHIVED&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;
					&lt;entry key=&quot;ADMIN_USER_ID&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;
				&lt;/map&gt;
			&lt;/entry&gt;
		&lt;/map&gt;
	&lt;/property&gt;
&lt;/bean&gt;

Then using code such as:

&lt;cfset constants = factory.getBean(&quot;appConstants&quot;)&gt;

You get a nested set of structures that may be used as constants.

I also noticed that you cannot use a bean with id=&quot;constants&quot;. This causes a bean creation exception.</description>
		<content:encoded><![CDATA[<p>For reference, the MapFactoryBean is a component available in the CVS version of ColdSpring. Using this component you can create a bean such as:</p>
<p>&lt;bean id=&quot;appConstants&quot; class=&quot;coldspring.beans.factory.config.MapFactoryBean&quot;&gt;<br />
	&lt;property name=&quot;sourceMap&quot;&gt;<br />
		&lt;map&gt;<br />
			&lt;entry key=&quot;product&quot;&gt;<br />
				&lt;map&gt;<br />
					&lt;entry key=&quot;STATUS_ACTIVE&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;<br />
					&lt;entry key=&quot;STATUS_INACTIVE&quot;&gt;&lt;value&gt;2&lt;/value&gt;&lt;/entry&gt;<br />
					&lt;entry key=&quot;STATUS_ARCHIVED&quot;&gt;&lt;value&gt;3&lt;/value&gt;&lt;/entry&gt;<br />
					&lt;entry key=&quot;user&quot;&gt;<br />
						&lt;map&gt;<br />
							&lt;entry key=&quot;STATUS_ARCHIVED&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;<br />
							&lt;entry key=&quot;ADMIN_USER_ID&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;<br />
						&lt;/map&gt;<br />
					&lt;/entry&gt;<br />
				&lt;/map&gt;<br />
			&lt;/entry&gt;<br />
			&lt;entry key=&quot;user&quot;&gt;<br />
				&lt;map&gt;<br />
					&lt;entry key=&quot;STATUS_ARCHIVED&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;<br />
					&lt;entry key=&quot;ADMIN_USER_ID&quot;&gt;&lt;value&gt;1&lt;/value&gt;&lt;/entry&gt;<br />
				&lt;/map&gt;<br />
			&lt;/entry&gt;<br />
		&lt;/map&gt;<br />
	&lt;/property&gt;<br />
&lt;/bean&gt;</p>
<p>Then using code such as:</p>
<p>&lt;cfset constants = factory.getBean(&quot;appConstants&quot;)&gt;</p>
<p>You get a nested set of structures that may be used as constants.</p>
<p>I also noticed that you cannot use a bean with id=&quot;constants&quot;. This causes a bean creation exception.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kevan Stannard</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-140</link>
		<dc:creator>Kevan Stannard</dc:creator>
		<pubDate>Fri, 09 May 2008 13:36:40 +0000</pubDate>
		<guid isPermaLink="false">#comment-140</guid>
		<description>Thanks Tom, Sean

I originally started off with a ColdSpring bean of constants, but when working on a ColdSpring / Transfer application I could not see a simple way to get my constants into Transfer Decorators, so I switched to cfm&#039;s.

However, just now found Brian Kotek&#039;s Transfer bean injector:
http://www.briankotek.com/blog/index.cfm/2008/1/14/My-Transfer-Decorator-Bean-Injector-Observer-Is-Now-Available

Thanks Brian!</description>
		<content:encoded><![CDATA[<p>Thanks Tom, Sean</p>
<p>I originally started off with a ColdSpring bean of constants, but when working on a ColdSpring / Transfer application I could not see a simple way to get my constants into Transfer Decorators, so I switched to cfm&#8217;s.</p>
<p>However, just now found Brian Kotek&#8217;s Transfer bean injector:<br />
<a href="http://www.briankotek.com/blog/index.cfm/2008/1/14/My-Transfer-Decorator-Bean-Injector-Observer-Is-Now-Available" rel="nofollow">http://www.briankotek.com/blog/index.cfm/2008/1/14/My-Transfer-Decorator-Bean-Injector-Observer-Is-Now-Available</a></p>
<p>Thanks Brian!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sean Corfield</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-139</link>
		<dc:creator>Sean Corfield</dc:creator>
		<pubDate>Fri, 09 May 2008 12:04:08 +0000</pubDate>
		<guid isPermaLink="false">#comment-139</guid>
		<description>Like Tom I use ColdSpring for this. I have a MapFactoryBean that is declared with all of the constants I need and then I have that injected into my CFCs. It&#039;s very clean and simple.</description>
		<content:encoded><![CDATA[<p>Like Tom I use ColdSpring for this. I have a MapFactoryBean that is declared with all of the constants I need and then I have that injected into my CFCs. It&#8217;s very clean and simple.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Chiverton</title>
		<link>http://blog.stannard.net.au/2008/05/09/using-constants-in-coldfusion-components/comment-page-1/#comment-138</link>
		<dc:creator>Tom Chiverton</dc:creator>
		<pubDate>Fri, 09 May 2008 08:23:52 +0000</pubDate>
		<guid isPermaLink="false">#comment-138</guid>
		<description>&quot;How do you handle constants in ColdFusion components&quot;
I have ColdSpring inject them, normaly from a Map in the ColdSpring XML though if their more complicated or user-dependant I&#039;ll do a fill blown &#039;EnvironmentService&#039; that can be injected into all the components.</description>
		<content:encoded><![CDATA[<p>&quot;How do you handle constants in ColdFusion components&quot;<br />
I have ColdSpring inject them, normaly from a Map in the ColdSpring XML though if their more complicated or user-dependant I&#8217;ll do a fill blown &#8216;EnvironmentService&#8217; that can be injected into all the components.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

