How to see if a function exists in a CFC

{ Posted By : Eric Cobb on January 21, 2011 }
2363 Views
Related Categories: Tips 'n Tricks, CFML

Just recently I came across a situation where I needed to determine if a specific method was available in a CFC. I have a case where I'm creating specific methods for specific departments. So in the code, if Department A has a method, do this, if not do that. As it turns out, this is super super simple to do from within the CFC.

How simple is it?
It is so simple that I couldn't believe it when I tried it and it really worked. I had to do a double take because, well, I'm really not used to my code working right the first time. I actually felt smert for a change, like I knew what I was doing!

More »

When is a Structure not a Structure?

{ Posted By : Eric Cobb on November 4, 2010 }
1497 Views
Related Categories: Tips 'n Tricks, CFML

A few days ago I was working on an application I inherited and needed to clear a structure that was stored in the session. No problem, right? Just use StructClear(). But every time I tried, I got an "Element is undefined" error. I knew the elements were there, I could output them with no problems. But for some reason, StructClear() refused to see my structure.

More »

Using an array to sort dates.

{ Posted By : Eric Cobb on October 7, 2010 }
1618 Views
Related Categories: Tips 'n Tricks, CFML, ColdFusion

Here's an interesting little tidbit I thought I'd pass on. Yesterday I had a case where I needed to select the latest date out of about 4-5 given dates. The dates could range anywhere from today to a year ago. My first inclination was to just have a bunch of CFIFs comparing the dates and filtering through and determine which one was the latest. But then, I thought about how easily arrays can sort values and wondered if I could apply that to dates as well. As it turns out, you can, and it's really simple to do.

More »

Using RepeatString to create a mask in NumberFormat

{ Posted By : Eric Cobb on September 2, 2010 }
1167 Views
Related Categories: Tips 'n Tricks, CFML

Today I was working on creating a CSV file that required numeric columns to be a fixed number of digits, using leading zeros to make up the difference. So, for example, if the column required 5 digits, the number 123 should show up as 00123. This is super simple using the NumberFormat() function in CFML, simply specify a mask like so:

<cfset variables.myNum = NumberFormat(123,'00000')>
<cfoutput>#variables.myNum#</cfoutput>

But, in my particular case, I had several columns that required 12 and 15 digit numbers.

More »

Accessing Application.cfc methods from Application.cfm

{ Posted By : Eric Cobb on March 30, 2010 }
2372 Views
Related Categories: CFML

This is pretty cool. I really had no idea that you could do this. (Now why you would want to do this is another story!)

As I mentioned in my last post, I've been spending a lot of time lately working on porting a legacy ColdFusion application over to Application.cfc. Everything has been going pretty well, until I started getting into sub-directories that have their own Application.cfm files in them. There's not a whole lot going on in these Application.cfm files, but each one of them is required and each one of them has a different name in its cfapplication tag.

More »

Query struct gets added to the Variables scope of Application.cfc, whether you like it or not.

{ Posted By : Eric Cobb on March 29, 2010 }
2442 Views
Related Categories: CFML, ColdFusion

I've been spending a lot of time lately working on porting a legacy ColdFusion application over from Application.cfm to Application.cfc on ColdFusion 8. One of the things I'm paying close attention to is what gets put into the variables scope inside of my Application.cfc. I don't want to accidentally have stuff floating around in there and causing problems. So, my constantly checking the variables scope of various methods is how I found this little gem.

Did you know that, even if a query name is var scoped in Application.cfc, you'll still get CFQUERY.EXECUTIONTIME stored in the variables scope of your CFC?

More »

Using a Java Object to replace blanks in a list.

{ Posted By : Eric Cobb on March 26, 2010 }
2294 Views
Related Categories: Tips 'n Tricks, CFML, Java

Today I was working on parsing through a CSV file, when I came across the all too familiar "ColdFusion ignores blank list elements" situation. This is nothing new, it has been around forever, and there's even an excellent udf on cflib that does a great job of handling this. But, I was feeling a little creative and decided to see if I could tap into Java and accomplish the same thing.

As it turns out, it was actually pretty easy to do.

More »

Using Java objects to loop through a directory and check date last modified on files.

{ Posted By : Eric Cobb on February 25, 2010 }
2537 Views
Related Categories: Tips 'n Tricks, CFML, Java

This is probably a no-brainer for some of you, but I was playing around with CFML's underlying Java capabilities the other day and thought I would share this little gem. Not that it's all that extraordinary, or even really useful, I've just got some free time and I haven't blogged anything in a couple of weeks so I figured "why not?".

More »

Discrepancies in the way ColdFusion validates dates.

{ Posted By : Eric Cobb on February 8, 2010 }
2185 Views
Related Categories: CFML, ColdFusion

There seems to be discrepancies in the various date validations used throughout ColdFusion, or at least I've found one case where it inconsistently considers a value a valid date. It's probably easier to demo what I'm talking about than to try to explain it. Here's an example:

More »

Problem with cfqueryparam and Oracle's char datatype.

{ Posted By : Eric Cobb on January 8, 2010 }
2358 Views
Related Categories: CFML, Databases

I ran into a problem this afternoon with cfqueryparam when querying an Oracle database that really had me scratching my head. In my query's WHERE clause I was filtering against a column that had a CHAR(8) datatype, but whenever I ran the query with cfqueryparam it wouldn't return any results.

More »

More Entries »