Wednesday, July 23, 2008

Populate coldfusion bean from query

I thought of a nice way to populate coldfusion beans from a query. It might be obvious, but we have code all over in our mach-ii application that explicitly calls setters on a bean after query. So following method got added to BaseComponent.cfc (thanks Hal Helms). It's not checking anything so the burden is on query to have the right data.

If you use generic setter the line:

can be replaced with:

So this allows me to do something like this:

Saturday, July 19, 2008

Object collection class with iterator

So I added an iterator to my collection cfc. Several people blogged about using java iterator for coldfusion arrays and looks like Transfer uses those.

Here is an iterator method:

I also changed getBy() and removeBy() to use iterator:

Also have to plug MXUnit. Using it made refactoring like that above, much more enjoyable.

Friday, July 18, 2008

Object collection class

This is collection cfc that's largely based on one I found here.

I added couple of methods, getBy and removeBy that I think will be helpful for working with collection of objects. Each takes a property and a value of that property as arguments, then we try to match those to one of the objects in the collection.

Now I need an Iterator for this.

Wednesday, July 16, 2008

Replacing notepad with notepad++

I discovered notepad++ and wanted to replace windows notepad with it. The instructions are here in the middle of the page under heading "Notepad Replacement". Well it turned out it's not that easy to delete notepad.exe. It kept on reappearing. So I found instructions here and it helped, I am reproducing instructions in case they disappear.

Create backup copy of c:\WINDOWS\notepad.exe
Change Explorer view options to show system files
In temporary folder: Have your new notepad.exe file ready
Copy the exe file into the clipboard ( select the file and hit Ctrl-C )
Open folder C:\WINDOWS\ServicePackFiles\i386 in Explorer
Open folder C:\WINDOWS\system32\dllcache in Explorer
Ctrl-V, Backspace
Ctrl-V, Backspace
Ctrl-V, Backspace

*Just for your information Ctrl-V pastes the new notepad and Backspace moves you up a directory. By doing this as outlined above you replace all of the default Windows notepad.exe files. Make sure you copy the notepad.exe that you want to use first by selecting that file and hitting Ctrl-C

Also one other note, for the first step where I said to replace notepad here:

on some computers it might actually be: C:\WINDOWS\i386 and notepad will have the name like: notepad.ex_ -- Simply copy the notepad.exe over the notepad.ex_ and make sure you keep that same file name with the underscore (or whatever symbol its using)

Tuesday, July 15, 2008

Mach-ii sub-application - part 2

To demonstrate sub-application setup I am going to use example application from mach-ii site called ContactManager. If you are going to follow along then download it and unzip into ContactManager folder under your webroot. After that you should be able to browse to it using http://[your-web-root]/contactmanager/

Next I made a folder under contactmanager called "subapp". Under that "config" folder. Also I made a subapphome.cfm file in the "views" folder to show something different in subapp. Just put any random text in that file. Look at an image of the ContactManager tree to see added elements.

Now we separate common elements into an include called mach-ii-common.xml

Those elements are removed from main applications mach-ii.xml, but we add an include before properties section

Here is sub-application mach-ii.xml

Notice the properties for SES URLs.

There is at least one issue with this setup is that links need to be relative to the web root so that they work from main app and from sub app. So in mainTemplate.cfm file I added "/contactmanager/" to all the links resource references at the top.
Here is an example, following lines


As you can see I also added a link to my sub-application.

After all this you should be able to get to your subapp by going to http://[your-web-root]/contactmanager/subapp/index.cfm/event/subapphome/

Monday, July 14, 2008

Mach-ii sub-application - part 1

Sometimes it's handy to make a sub-application in mach-ii. Config file gets rather large rather quickly at times. One thing to understand is that sub-application is not a completely stand alone app. It relies on the main application. Mach-ii 1.5 introduced modules and includes so some of the issues of breaking out large chunks of configuration and code that are solved with those.

However one use case just came up where I wanted to have only part of the application to have SES URLs. So by breaking out this new part of the application into sub-application I could reuse layout and user tracking from the main one but use new SES properties (also introduced in mach-ii 1.5) in subapp. I think I could also put common properties, event-handlers, listeners, e.t.c into an include that way duplication of code will be minimal.

I am going to demonstrate this in the next post.

Friday, July 11, 2008

ColdFusion Code Highlighting for a blog

One thing that's keeps me amazed is that every time I need to solve something, someone somewhere already encountered that issue and most likely solved it. This is especially true for all things computer. I pretty much expect this behavior. So this proved true as I ventured to find a way to have code highlighting for my blog.

Thanks to Aaquagua!: Web Page Syntax Highlighting for ColdFusion - Brush for SyntaxHighlighter post I was able to add code highlighting. Not only he had instructions for adding SyntaxHighlighter but also added ColdFusion brush. How cool is that?

One thing I want to add though using <textarea> insted of <pre> tag worked better. When using <pre> it adds closing tags for some reason for ColdFusion tags that are not closed. Here is an example of this behavior:

<pre name="code" class="cf">

// comments
var bar = 1;
return foo+bar;


<textarea name="code" class="cf" >


Turns out the above mentioned problem is dependent on a browser. IE7 seems to be fine FF2 and FF3 have an issue mentioned, and Opera blew up completely.

So use <textarea> since that seems to be working in all browsers

Thursday, July 10, 2008

Custom domain for my blog

I registered a domain for my blog, actually two: and (second one is way too fruitty). The domains were registered and parked at makes it very easy to have your parked domain pointed to blogger.

Also it's a free feature on blogger. WordPress for example charges $10 a year to have your personal custom domain to point to your blog.

I wonder why Blogger doesn't have categories for posts? They have labels so it's probably almost the same and keeps with the google theme.

I think Blogger might be temporary solution. I would like to use some ColdFusion based blogs, maybe machblog or Mango blog.


After avoiding blogging scene for years I finally decided to give it a try.

The most important reason is to remember my own findings. Right now I am working as ColdFusion Developer / Architect and there is slew of new things that are being researched, reviewed and implemented. So this is a way to keep track of my findings and thoughts.

Also I do find other peoples blogs helpful occasionally so perhaps this will be a way to give back to the community.