ColdFusion Builder - Code Assist for Scoped Variables

This post is more than 2 years old.

Heres an interesting ColdFusion Builder feature you may not be aware of. CFBuilder does a good job providing code assistance for CFCs. So for example, consider the following code snippet:

<cfset ob = createObject("component", "test")> <cfoutput>#ob.

As soon as I hit the dot, CFBuilder introspected my test component and provided the following visual feedback:

CFBuilder is even smart enough to notice private methods. When I changed my drinkBeer to a private method (which sounds kinda sad), it didn't show up in the drop down. However, most of the time we don't work with CFCs like that. Instead we create them on application start up and store them in the Application scope. Wouldn't it be nice if you could get the same code assistance after typing the application scope version of the CFC? The good news is that you can.

In order to use this feature, you need to go into your project properties. Once you've loaded the project pane, select: "ColdFusion Variable Mappings":

For my test, I'm working within the BlogCFC project. I'm going to create a mapping between application.blog and the CFC:

Once I've done that I can then get code assistance on my application variable:

Pretty nifty, eh? As you can guess, setting up these mappings will be a manual process. However, in most projects I'd assume you have a core set of CFCs that act as services. While you may have a large number of components in play, the "core" ones you use will probably be a smaller number. A few minutes of set up and your good to go. One little nit - be sure not to typo. For some reason Adobe included the ability to add and delete mappings, but not to edit them.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Archived Comments

Comment 1 by Joshua Cyr posted on 3/10/2010 at 2:35 AM

Wow, I missed that. Very useful. Great time saver. woot!

Comment 2 by Hem Talreja posted on 3/10/2010 at 3:10 AM

Ray,

It would be nice if we could add Meta Data Tag just about the definition of the variable to help CF Builder do the Variable Mapping.

example:
<cfscript>
// [CFCPath="com.hemtalreja.test.MyObject"]
myObject = Application.beanFactory.getBean("myObject");
</cfscript>

Comment 3 by Jeremy posted on 3/10/2010 at 9:28 AM

Too bad it only work if you create a new project with "ColdFusion Project". The option is not available when created project from SVN.

Comment 4 by Raymond Camden posted on 3/10/2010 at 11:24 AM

Incorrect Jeremy - I use SVN with CFB. If you made the project via SVN, you can just associate the CF nature with it (or some such, I forget the exact term), but the point is, you _can_ do it.

Comment 5 by Marcel posted on 3/10/2010 at 6:53 PM

Settings are saved in the settings.xml file in the project root path. You can easy generate the XML file based on your cfc locations and application structure. You can add this file to CSV/SVN to share with your fellow developers.

I've generated one for myself, to be save I had closed my cfbuilder before, at startup he will read the new file and works fine.

Comment 6 by Joshua Cyr posted on 3/10/2010 at 6:57 PM

The xml doc is nice and simple. I wonder if an extension can be made to inspect app.cfc and update automagically? I am sure it would be easy to write, guess the question is if you can alter that xml while in the project. Sadly I wont have time to tinker till this weekend.

Comment 7 by Faisal Abid posted on 3/10/2010 at 7:38 PM

Wow thats pretty sweet!

Comment 8 by Danny Scott posted on 3/10/2010 at 8:19 PM

Great tip. I love coldfusion builder. So much so that I'm willing to put up with the frequent crashes.

My builder seems to just randomly lock up and have to be killed from the task manager at least once per day. Has anyone else experienced this issue?

Comment 9 by Raymond Camden posted on 3/10/2010 at 8:23 PM

@Danny: Obviously I can't say much under NDA, but I will say that performance/stability has seen MASSIVE updates since the last public beta.

Comment 10 by John Allen posted on 3/10/2010 at 10:49 PM

Very very nice.

Comment 11 by Jeremy posted on 3/11/2010 at 3:31 AM

@Ray. Thanks. After your comment, i spend a little time to investigate. I just need to modify the file .Project to make it work :) . All my project was created when using cfeclipse, so it doesn't have that.

Comment 12 by Brian Meloche posted on 3/22/2010 at 4:04 AM

Does your project need to be at the root?

I've tried to make this work, but it never has... I get no code assist at all. I'm guessing I'm doing something wrong, but it just doesn't work for me.

Can you describe how your project is built/structured? For me, I am using a virtual host, which is pointing a few directories under the main root of localhost.

Comment 13 by Brian Meloche posted on 3/22/2010 at 4:41 AM

Disregard. I figured it out. Your project must have the same root as your virtual host. I had my projects back a few directories behind the root, which is a typical feature for several of my projects. I created a new project at the root, and voila, it worked! I will just have to include the directories I need behind the root going forward.

Comment 14 by Andrew Abbott posted on 4/9/2010 at 10:28 PM

Just FYI I mapped to a scoped variable pointing to a cfc that extends other cfcs, but I just get the list of methods in that cfc and not the inherited methods. Still..it is a cool feature!

Comment 15 by Darren Cook posted on 5/5/2010 at 11:02 AM

@Brian and anyone else who notices that CF Variable Mappings are relative to your project folder...you can use linked folders to overcome this. I posted instructions here:
http://darrentcook.wordpres...