Tuesday, December 4, 2007

Handling whitespace in ColdFusion

ColdFusion contains a number of tags to help prevent whitespace being returned to the browser. There is a nice blog on this here.

I tried applying those recommendations above, but kept on getting whitespace produced. To complicate my problem, processingdirective for suppresswhitespace=true seem not to do much within CFCs at all. Tried putting them at various places (within and outside methods in a CFC to no avail). Even worse - if you put a processingdirective before your CFC CFCOMPONENT on top it completely breaks. I suppose this is more of a problem on my end as there's I'm sure a reference point somewhere saying you can't do that.

Anyways, the weird and irritating thing was that the MSSQL Server kept on getting data with some funny characters in front of it (sort of a box). I had a call to do a trim and then a cleaning method that replaced some characters in a string before its fed into a CFQUERY. Turns out that the only way to get rid of those "boxes" (as well as the whitespace) was to use CFSILENT in my CFC. One is placed after the CFCOMPONENT tag on top and the other way at the end. This seems to do the trick nicely!

No comments: