1-10 of 22
Advantage of request scope over application scope
Title: Advantage of request scope over application scope
Thread posted on Mar 27 by
Its advantageous to use request scope instead of application scope.
A perfect example will be the use of the dsn name.
You've probably seen the use of a variable called "application.dsn" (or "application.datasource") in code. Perhaps you've even been taught to use the method in a class.
Maybe you've even been doing it in your own code. I'm talking about setting this variable in the application.cfm file to hold the name of your data source for a given application.
It seems so innocuous, and it seems to provide ways to make your code easier to maintain (change the dsn variable once in the application.cfm, and all the templates that use it under control of that application.cfm get the benefit of the change).
However, there's a problem and it can be a nasty one. This issue has to do with the locking of (or failure to lock) shared-scope variables such as this one, and the fact that rarely does any discussion of this approach include the consequences of using shared variable scopes. There have been other articles in CFDJ on the subject of shared variable locking, as well as Macromedia Knowledge Base articles.
Maybe you didn't make the connection between them and this issue. This article puts the problem in perspective and offers some explanations of how to understand and resolve it. The ultimate solution involves using a "request"-scoped variable instead of an "application"-scoped one.
If you're not familiar with shared variable scopes, or are fuzzy about locking issues, or perhaps have never understood what "request" scope variables are about, this article should help you.
If you do understand these things, change your references to application.dsn to request.dsn, and if you find any locks around code that was using such an application.dsn variable, you need to consider whether those should stay as well. I'll also offer insights into how to find and fix such locking references.
You may see code doing this in application.cfm:
<CFSET application.dsn = "whatever">
which declares the variable as "global," in essence, and can therefore be used later in all other templates as in:
<CFQUERY datasource="#application.dsn#" ... >
to refer to that data source name. The upside to this is that if the data source name needs to be changed (from "whatever" to "whatever_test", for instance), you can simply modify the application.cfm to point to the new name, and all templates under its control get the benefit of the change.
It's a good plan, but the use of an application-scoped variable is flawed. It opens you to potentially troublesome locking issues (for more on that, including a good explanation for why it's a problem, see "ColdFusion Locking Best Practices" at www.allaire.com/Handlers/index.cfm?ID=20370&Method=Full). More important, you can have the intended benefit with an equally useful and less troublesome way.
For reasons I'll explain in a moment if it's still unclear, I'm suggesting that you stop using the application scope to hold the data source name. However, instead of dropping "application." from the variable name, I'm suggesting that you use the "request" scope. In other words, do the following (in your application.cfm):
<CFSET request.dsn = "whatever">
and then in all your templates do:
<CFQUERY datasource="#request.dsn#" ...>
If it's not clear why this is useful, or how it works, then there may be confusion about:
- How the application.cfm works like a CFINCLUDE (and how we could, but won't, use a local variable called "dsn")
- What the request scope is about (and why it's better to use "request.dsn")
Let me explain both. Though it would seem that many understand the first point, I find they often don't and it's fundamental to the rest of the discussion. The use of request scoped variables is also poorly understood by many. The end result is that you'll no longer have to deal with locking issues with regard to this variable.
How Application.cfm Works Like a CFINCLUDE
And How We Could, but Won't, Use a Local Variable Called "dsn"
Nearly every CF developer knows that whenever a CF template is run, CF first tries to execute any application.cfm that exists in the same directory (or its parent directory, or its grandparent, and so on).
What may not be obvious is that CF actually runs the application.cfm like a CFINCLUDE, which means that any variables set there, including "local" variables (such as <CFSET firstname="bob">), are then available to the template that was originally being run.
So let's say we have a template that does the following:
If it did this and nothing else, you might expect it to fail since you can't refer to variables that don't exist, and it's only outputting the variable, not creating it. But if firstname was set in application.cfm (assuming this template is in a directory controlled by that application.cfm), it can indeed refer to the variable.
Knowing that, you may wonder why the folks who promoted this solution of setting the dsn variable to the application scope even bothered. They could just as easily have said:
<CFSET dsn = "whatever">
and then in all their templates do:
<CFQUERY datasource="#dsn#" ...>
It would work. In fact, there's no need to be using the application scope to pass the variable to all templates (make it global), because any variables set in the application.cfm "trickle down" to all templates, in effect making them global. There are certainly good uses of application scoped variables, but this isn't one of them.
The simple example of setting a variable called "dsn" (or what could be formally specified as variables.dsn, which is the same thing) to hold the name of the data source would work, and would trickle down to all the templates. It's effectively "global," at least for the life of that template, and it's reset at the execution of each template by being executed in the application.cfm each time.
I've recommended that you use "request.dsn" rather than "dsn" or "variables.dsn". Why? And what is the request scope, anyway?
What the Request Scope Is About
And Why It's Better to Use "Request.dsn"
If you understand that setting a local variable called "dsn" will work, can you think of any situation in which your code may expect to have access to that variable but won't? Think hard. Okay, custom tags. Yep, most know that custom tags have their own local variable scope. So a local variable set in the caller (or in the application.cfm) won't be available to the custom tag.
When we were setting the dsn variable to an application scope, it was available in the custom tag (as are all shared scopes and also form, url, cgi, and other variables that are passed to the calling template).
By changing the application.dsn variable to dsn (or variables.dsn, same thing) while it's available in all templates under control of the application.cfm, it's not available to any custom tags called by those templates. That's why we need to use the request scope instead.
Its sole purpose, poorly understood though it is, is to create local variables in a program that are available within custom tags called by that program (and vice versa). That's it. Nothing more.
Many confuse the request scope with some sort of persistence or shared nature (and the fact that there's a different kind of "request" scope in other languages like ASP and JSP only confuses matters further). It's best to think of it as nothing more than a scope that allows local variables to be seen in a custom tag called by the template setting the request scope variable. And since our request.dsn variable is set in the application.cfm, it trickles down to the template being executed and is therefore also available to any custom tags we call as well.
That's why you should use the request scope rather than a local scope.
Remediation of Application.dsn Misuse
One last thought: you may not be able to blindly do a global search and replace application.dsn with request.dsn wherever it occurs. Depending on the savvy of the coder, the use of application.dsn may have at least two wrinkles that require more care than just replacing application.dsn with request.dsn:
- You may be testing for the existence of application.dsn before setting it in the application.cfm, in which case you need to set the request.dsn outside that test since it will never "already exist."
- You may have CFLOCKs surrounding CFQUERYs, or CFLOCKs that are moving the application.dsn to a local variable. You wouldn't want to just rename the scope in those instances.
Each of these cases requires a little more care to resolve. I provide further insights into solving these problems on my Web site, www.systemanage.com/cff/application_dsn_bad.cfm
I hope this article not only helps prevent problems with application.dsn, specifically, but also increases your understanding of request scope variables and application.cfm processing in general.
Advantages of application.cfc over application.cfm 1
Title: Advantages of application.cfc over application.cfm
Thread posted on Mar 31 by
We all seem to know the difference between these two files.
But it will be of great help if everyone of you can share your views regarding the above topic.
Bangalore Campany list - using coldfusion for development 2
Title: Bangalore Campany list - using coldfusion for development
Thread posted on Apr 07 by
Here I mentioned some of the bangalore companies, Which are using coldfusion for the Software/Web development.
Adobe - www.adobe.com
Accenture - www.cccenture.com
ACS - www.acs-inc.com
Adea - www.adea.com
Arctern - www.arctern.com
Bob Technologies- www.bobtech.com
Honeywell - www.Honeywell.com
IBM - www.ibm.com
ionidea - www.ionidea.com
Mindtree - www.Mindtree.com
Ness - www.ness.com
Nuware - www.nuware.com
PSI Data systems- www.psidata.com
Please extend this list. It may help to jobseekers.
ColdFusion Tree with Checkbox functionality 3
Title: ColdFusion Tree with Checkbox functionality
Thread posted on Oct 18 by
Dear ColdFusion Friends,
I am looking for the functionality to render the tree with Checkboxes feature where enabling parent node enables the child nodes too and disable the childnode will not enable parent node.
Please share ideas with which i can achieve this. you can email me to on email@example.com too.
Thanks and Regards,
Raghuram Reddy Gottimukkula
Member Bangalore CFUG
Create Flash Applications for Forum Nokia, Win Great Prizes
Title: Create Flash Applications for Forum Nokia, Win Great Prizes
Thread posted on May 28 by
If you work on Adobe Flash Lite, its time to make your mark on the world stage. And that too on a global platform as big as one with the Forum Nokia brand name.
There is a special category for application designed on Flash for mobile devices, (especially for 60 and most Series 40 devices). Flash applications which make the most of touch-based input methods have a better chance of winning the contest.
If you win the contest, the whole world will sit up and take notice. Plus, you get a chance to work with Nokia, get a premium placement for your application on their Ovi Store and win mega prizes worth $250,000.
For more details visit http://www.callingallinnovators.com
Excellent Platform for Flash Lite Developers
Title: Excellent Platform for Flash Lite Developers
Thread posted on Nov 19 by
Are you thinking of creating some innovative mobile application with Flash Lite? Then the Forum Nokia Developer Conference is an excellent platform for you to share your ideas and creations. It is a great opportunity for developers not just to showcase their ideas but also get to learn from other developers and the Nokia leaders and experts. Apart from Flash Lite developers, Symbian, Maemo, Qt and web developers too are invited for the conference which will be held at Taj Residency in Bangalore, India on 7th December.
For more details, check out http://www.nokiadevcon.in/index.php
Forcing CFC Documentation with Unit Tests 1
Title: Forcing CFC Documentation with Unit Tests
Thread posted on Mar 30 by
Here's a unit test I wrote today that makes sure every public CFC function has a hint attribute specified:
<cfset var md = GetMetaData(variables.instance)>
<cfset var i = 0>
<cfset var f = "">
<cfif IsDefined("md.functions") AND ArrayLen(md.functions)>
<cfloop from="1" to="#ArrayLen(md.functions)#" index="i">
<cfif NOT StructKeyExists(md.functions[i], "access")
OR LCase(md.functions[i].access) IS "public">
<cfset assertTrue("Missing hint on function: #md.functions[i].name#",
You might need to replace the
variables.instance with an instance of the component you are testing.
Is there a way to solve this? 2
Title: Is there a way to solve this?
Thread posted on Oct 16 by
I am a newbie in cold fusion.
Below are the 3 cold fusion page. Similar to MyPage.cfm, there are other tabs. Now the application has regular html controls.We haven't used any cf controls like cfgrid in our application. How Can I get <CFFORM> to make it work in this scenario and to use cfgrid?
If this is not possible, does regular html <form> can handle <cfgrid> feature.?
Can somebody help me out with this case?
<form action="post" action="SQL/#submitPage[SelectedTab]#" >
Model Glue architecture flow 2
Title: Model Glue architecture flow
Thread posted on Mar 26 by
I am in some confusion with the model glue architecture flow.
Please share the info. related to the viewstate and how exactly it works for the MVC.
If you have given the flow with steps/diagrams it will be appriciated.
Thanks in advance,
Adobe certified coldfusion devleoper
My Experience with Coldfusion Builder 1
Title: My Experience with Coldfusion Builder
Thread posted on Aug 21 by
Hi cf friends,
Being a coldfusion developer for the last 2 years, my style of debugging is more like cfdump, cfabort and enable the debugging mode all the times.
Coldfusion builder, i guess this is the second IDE which developed for the coldfusion developers specifically. First one is CFEclipse.
2weeks back, installed Coldfusion Builder and started using/looking into the features how exactly useful in local,remote server environments for coding, ftp, rds, debugging, cfc creation, extensions,cfnature and ORM etc etc...
So instead of clubbing all the features all together, i wanna make some points.
1. CFBuilder :: Coding
This IDE has common features like content suggest, auto tag closing,highlighting matched content, expand/collapse tag hierarchy and syntax check/suggestion are some common features.
a.Content suggest has intelligence that it will not show the already selected/written attributes. It means, if name attribute for cfquery tag is already existing, it will show remaining attributes other than name.
b. As soon as you type datasource=, it will show the datasources available in the system.
Its same with the object creation for particular component. with in createObject function it will show the all the cfc path to select. so no need of worrying about the correct name for datasource and correct path for cfc.
click on the cfc path or function, it will take you to that cfc.
Sounds good right!
c. Refactoring: If we want to change function name in a application, we used to search for all the functions and replace manually in dreamweaver. Now this IDE will identify which is function/variable, based on our selection it will modify particular functions/variables in the application.So it will reduce the time/risk in changing function/variable/object names.
2. CFBuilder :: Dealing with servers
a. Just add a server to cfbuilder by providing host name, port number(8300 for cf8/8500 for cf9), cfadmin login credentials document/web root and server root(JRun path).
With this setup,
we can view the server log in cfbuilder server console it self.
we can manage(start/stop/restart/refresh) server right from your IDE.
(No need of going to services to restart server. If you have multi servers like apache and coldfusion, you have to restart both.That case it is one click away to restart both the server in cfbuilder.)
we can check the errors while debugging.
b.we can connect to RDS just like the above setup.
3. CFBuilder :: FTP
cfbuilder will support FTP and SFTP connections.
so we can synchronize our coldfusion project with the remote code by providing host details and mapping path.
4. CFBuilder :: Debugging
create project with the code which you have in local, by providing web root/context root,port number etc..
Add the server to that project, which we have already added to cfbuilder. Open the file which you want to debug.
Keep breakpoints, where you want to stop the flow for debugging. Run the application.
As soon as the flow comes to break point, it will stop at the break point and you can view the variable,scope variables(request,session,application...)/structure/object holing values and you can verify the execution flow by clicking on next.
For viewing variable holding values, you have to select window > show view >Debug > variable etc...
Ensure that you enabled line debugging(debugging and settings > debugging) in coldfusion administrator before start debugging.
After enabling you have to refresh the server for taking new changes(enabling line debugging) in server settings.(in cfbuilder server wizard,select the server and right click to refresh. coool right!)
create project,provide remote path,add remote server and start debugging.
while adding server, based on your ip address/host name it will identify the remote server and shows the status as remote in server wizard.
5. CFBuilder :: CFC creation
cfc creation is very simple with cfbuilder.
select the table for which you want to create cfc through RDS wizard and right click on it.
you will find create cfc option, just click it.
Tell you boss that, i have created 10 cfc's in 1 minute :)
6. CFBuilder :: Extensions
An year back, for creating sample application(hello world and login module) in model-glue, it has taken 2 days for me.
cfbuilder has model-glue extension. The procedure is very simple(of course, its the purpose of extension).
Go to navigator. Right click for project creation. provide project location and select the extension(enable check box).
click on finish.
you are done with model-glue hello world application.
if you specify application root while creating project, it will create the code accordingly. No worries :)
Hello coldfusion world...Its beautiful..........I like it...why because i struggled for that by downloading, copying, changing path etc etc.
some of the other extensions i found are cfparam checking etc...(I will update you after a try)
you got hello world application.
How intelligent it is :)
7. CFBuilder :: CFNature
suppose that you have created a java project and you want to change it as coldfusion project.
Just right click on your project in navigator window and select CFNature.
Done. your project got changed to coldfusion project.
If you are not believing, check the project icon before and after applying CFNature.
Funny thing happened with me is like, i used this option and checked all the files. I found no java file changed into cfml. Later i came to know that, the properties of the project and the icon will change.
I shared this with my friend sadashiv, who is sitting next to me.
Now a days he is teasing me by calling "Raghuram Nature".
8. CFBuilder :: ORM
I need to use this option ........will update very soon.
Problems i faced during set up and usage are:
If you face any jvm error: Need to update jvm.config file with the path specified in coldfusion admin line debugging screen.
I guess,if you are using cf9, this problem will not come.
while using ftp,restarting servers through cfbuilder, have some patience. Don't click again and again until it hangs :)
cfbuilder has to update the features in UI development area like browser compatible check,designer view,drag n drop controls, UI templates like dreamweaver.
Thanks for reading my experience with cfbuilder.
If you have not installed yet, here are links for the free download:
CFBuilder installation is available at : http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_coldfusionbuilder
And how to use help pdf file at :http://help.adobe.com/en_US/ColdFusionBuilder/Using/cfbuilder_beta_help.pdf
Please send your suggestions to firstname.lastname@example.org to make this blog worthy.