Multiple Column Output
Posted by Ryan Heldt in ColdFusion on June 21, 2011
Displaying a query result in one or more columns is a pretty common task for the CF developer. However, for some reason, this is one of those things I can never remember how to do. So, in lieu of committing this to memory, I'm posting this here.
<cfset intColumns = 3 /> <table> <tr> <cfoutput query="qryData"> <td style="width: #int(100/intColumns)#%;"> --output goes here-- </td> <cfif qryData.CurrentRow mod intColumns is 0></tr><tr></cfif> </cfoutput> </tr> </table>
To catch a shooting entityDelete()
Posted by Ryan Heldt in ColdFusion on January 30, 2011
I’ve been using ColdFusion 9’s ORM features on a couple projects recently. That coupled with Sean Corfield’s excellent FW/1 framework has made short work of a lot of time-consuming tasks. Anyway, I’ve ran into a little bit of a snag around referential integrity.
If I use entityDelete() function to delete a record and there’s a constraint violation (in this case, a song category that’s associated with a song), I get the following error:
coldfusion.orm.hibernate.HibernateSessionException: Cannot delete or update a parent row: a foreign key constraint fails (`databasename`.`songs`, CONSTRAINT `songs_ibfk_3` FOREIGN KEY (`SongCategoryID`) REFERENCES `songcategories` (`SongCategoryID`)). (Database)
That’s obviously to be expected. Constraints are put in place to prevent such things. However, for whatever reason I can’t trap this error using try/catch.
<cfscript>
transaction action="begin" {
try {
entityDelete(local.objSongCategory);
} catch (Any e) {
transaction action="rollback";
}
}
</cfscript>
I can't think of any reason why this cannot be caught. Anyone have any thoughts?
CFEclipse: Highlighting Occurrences
Posted by Ryan Heldt in ColdFusion , Tools on January 21, 2011
I always liked the occurrence highlighting featured in a number of text editors, including Notepad++. Double-click on a word somewhere and the editor highlights other places in the same file where that word appears. Needless to say, I was pleasantly surprised to find this was something CFElipse has offered for some time and it's been under my nose the whole time.
On the toolbar is a non-descript 'forward arrow' looking button. Click it and occurrence highlighting is on. Alternatively, you can use ALT+SHIFT+O to toggle.

I didn't care for the default gray highlight color -- wanted something that stands out a bit more. After a bit more poking around, I found this could be changed in the Eclipse Preferences window under General > Editors > Text Editors > Annotations. In the annotation types list, you'll find a 'CFEclipse Mark Occurrence' option. Change the display options to your liking.

Awesome Free Mock-up Software
Posted by Ryan Heldt in Tools on January 11, 2011
During the software development process, I've found most clients have a hard time visualizing what you're planning on building them -- even with extremely detailed specifications. In the past, I've used slick product called Balsamiq for building mock-ups of the user interface and business processes. Including these visual aids along with the specs made things a lot clearer for the client as to what they were getting. If something wasn't quite how they wanted it, everything could be quickly modified, long before a line of code was written. The amount of time saved on one project alone could easily justify it's $80 price tag.
As luck would have it, I've run across something even better. Evolus has a similar prototyping tool called Pencil which has the fast majority of the features Balsamiq offers, and then some. Among these are the ability to have more than one mock-up per document (I remember having a whole folder of mock-ups per project when I used Balsamiq). Pencil also offers native interface widgets, in addition to the sketchy style. While Balsamiq offers sketchy only, they do have a lot more widgets.
Pencil is built on the Mozilla Framework, and although I prefer the standalone version, it's also available as a Firefox plug-in. Best part is its price tag: free! Licensed under the GPL (version 2), it's available under Windows and several flavors of Linux. Sounds like a Mac version is also in the works. Overall, I love the software and look forward to using it more.

E-mail Obfuscation
Posted by Ryan Heldt in ColdFusion on December 28, 2010
I needed a quick and dirty way to obfuscate e-mail addresses from the various harvesters of doom out there, so I came up with the following. Enjoy!
Example 1: #obfuscateEmail("someone@special.com")# Returns an obfuscated e-mail address.
Example 2: #obfuscateEmail("someone@special.com",true)# Returns an obfuscated e-mail address wrapped inside a mailto: link.
<cffunction name="obfuscateEmail" access="public" returntype="string" output="false">
<cfargument name="email" type="string" required="true" />
<cfargument name="generateLink" type="boolean" required="false" default="false" />
<cfscript>
var strReturn = "";
var strMailTo = "&##109;&##97;&##105;&##108;&##116;&##111;&##58;";
var intIndex = 0;
for (intIndex=1; intIndex lte len(arguments.email); intIndex++) {
strReturn = strReturn & "&##" & asc(mid(arguments.email,intIndex,1)) & ";";
}
if (arguments.generateLink) {
strReturn = "<a href=""" & strMailTo & strReturn & """>" & strReturn & "</a>";
}
</cfscript>
<cfreturn strReturn />
</cffunction>