Passionate Development From Journeyman to Master

cfargument gotcha

I encountered 2 ColdFusion gotchas today, blogging them here so that I won't forget.

First one has to do with cfargument, have a look at the code below:

[code=”cf”] <cfargument name=”mode” default=”custom” required=”false” type=”string” /> <cfargument name=”clientID” default=”” required=”false” type=”numeric” />

	<!--- The rest of the code here -->


Can you spot why the code won't working? When I call the function:

[code=”cf”] qFields = oJobBoardService.getFields(); [/code]

Here is the error that I get:

The CLIENTID argument passed to the getFields function is not of type numeric.

It's a bit confusing at first, you see when I call the function I didn't pass any arguments into it, but why the error indicate that ClientID was passed in?

I finally found out that it's because I set the default value for ClientID as empty string while I specified the argument type as numeric. Changing the default to 0 fixed the error. When you think about it, it kind of makes sense that ColdFusion validate the default value as well not only the supplied value.

Ah, another lesson learnt!