Managing Whitespace With CFC Output Attributes

A good rule of thumb inside a ColdFusion Component (CFC) is to set BOTH the output attributes of cfcomponent and cffunction to false.

<cfcomponent output="false">
    <cffunction name="foo" output="false">
    </cffunction>
</cfcomponent>

Normally I would think that the cffunction tag would inherit the output attribute and set its output attribute to false as well. However this is not the case.

The output attribute for cfcomponent only controls output in the constructor area, or everything outside of the functions. The output attribute for a function controls output only inside that function.

The other point to be aware of is if the output attribute is on, then any expression inside the pound(#) sign will be evaluated. If the output attribute is set to false then any expression inside a pound(#) sign will not be evaluated unless surrounded by a <cfoutput> tag. Rarely is there a need to use the pound(#) signs inside a function anyway unless it’s being evaluated in an attribute such as in <cfmail> or <cfswitch>. (See Mark Kruger’s blog on this)

Thanks to Ray Camden and O’Reilly’s Web Devcenter for enlightening me on this one.

Here’s another related article dealing with memory issues regarding use of the output attribute: http://wiki.mxunit.org/display/default/How+cfcomponent+output%3Dtrue++can+affect+memory+consumption

Turning New Lines Into HTML Line Breaks

Many times you need to process textarea field content in ColdFusion and add HTML line breaks so it actually displays correctly on screen or in an email. An easy way to accomplish this is to replace the character codes 10 and 13 with <br>:

Replace(textVar, "#Chr(10)##Chr(13)#", "<br>", "all")

This code takes:

Line 1
Line 2

Line 3

And turns it into:

Line 1<br>
Line 2<br>
<br>
Line 3

varScoper 1.30 CFBuilder v1 Issues

I just installed varScoper 1.30 CF Builder (version 1) extension on my machine, but found a few issues getting it to run.

  1. Make sure you put the varScoper folder in your Document Root you defined in your Server Settings. On mine this is the directory for my localhost.
  2. Modify the cfbuilder.cfm file, in the handlers directory, and add:
    <cfsetting showdebugoutput="false">
    

    to the beginning of the file. You may need to open NotePad with Administrative privileges I found out for some reason.

  3. It appears the “Description” window in the “Extensions” tab is broken for this extension. There is no fix as of right now.

Thanks to Ray Camden for the help on this.

ColdFusion Application.cfc Differences For This and Application Scope

Thanks to Ray Camden, I learned something new today that was of great help.

Inside the Application.cfc, I always assumed the “this” and “application” scopes where the same. This is incorrect.

“Application” scope will only store name/value pairs. It has no impact on how the application behaves on the server level (built-in behavior).

<cfset application.name = value>

While “this” scope is used to change the behavior of the application itself.  For example: defining custom tag paths and the common datasource name.

<cfset this.name= value>

CSS Equivalents for the pre Tag and nowrap Attribute

Rarely have I used the <pre> tag or the nowrap attribute in my code. However it is there, and I haven’t even considered if there was a CSS alternative. Today I ran into the CSS property for these that I’ve never seen before; the white-space property.

Example:

p {white-space: nowrap}

The possible values are:

normal

nowrap – same as the nowrap attribute

pre – same as the <pre> tag

pre-line – text wraps when necessary and on line breaks

pre-wrap – whitespace is preserved by the browser (same as &nbsp;) and text will wrap when necessary and on line breaks

inherit – ( not supported by IE, including version 8 )

For additional reference see https://developer.mozilla.org/en-US/docs/CSS/white-space

Ternary Operator within ColdFusion 9

For the first time today I used ColdFusion’s new ternary operator. I learned about it last week as a alternative to the inline-IF (IIF()). No longer do I need to remember the quarks about the DE operator required in IIF.

A ternary operator takes three arguments: ((condition) ? trueStatement : falseStatement)

Example:

<tr class="#(currentrow mod 2) ? 'lightRow'  : 'darkRow'#">

This can also be done using inline if:

<tr class="#IIF(currentrow mod 2, DE('lightRow'), DE('darkRow')#">

Or using cfif:

<tr class="<cfif currentrow mod 2>lightRow<cfelse>darkRow</cfif>">

As you can see, you can use a simple inline operator without having to worry about IIF quirks or drawn out conditional statements. Remember this is introduced in ColdFusion 9.

My New Xbox Kinect 360

Today I made an impulse purchase. I bought a Xbox 360 with Kinect package for $300. I was pretty impressed about the Kinect in their promotional videos and was looking for something a little better than my Wii I had before.

First mistake was not looking more closely at the box. I bought a controller for a whopping $45 thinking one wasn’t included.

The first issue I have is not enough space with the current arrangement of my apartment. It says I need 6ft of space, which I have, but apparently that’s like the bare minimum – even with the thing temporarily rigged all the way back on the wall.

Now, not only did I not have enough forward-backward space, but I was dumb enough to not push my coffee table all the way out of the way. So now I have a nice bruise on my thumb from smacking it on the table. Ouch!

Setup and use is pretty easy, though there seems to be a bit of “crapware” included.

The Kinect motions where pretty slick, though a little artificial. I can’t say I’ve seen anything like it before.

The sensor moves up and down to track you better on its own, recognizes your face, picks up your hand position, and enables voice recognition. Pretty smart if you ask me.

The game “Adventures” that came with it was pretty neat. But the rafting game wanted me to jump up on down to clear the raft of the logs. Well, that’s a bad deal because I live in an apartment on the second floor with only wood and drywall between my feet and the downstairs apartment. I’m sure they would love rattling lights.

I look forward to playing with the console more, but I’m done for the night and now watching Aguilera screw up the National Anthem.

Resetting RDP Sessions for Windows Servers via Command Line

I’ve needed this info many times, so I figured I should probably put this down in my blog. If you encounter the error: “The terminal server has exceeded the maximum number of allowed connections” and “The system can not log you on. The system has reached its licensed logon limit. Please try again later. Please try again or consult your system administrator.” while trying to RDP into a Windows Server, that probably means someone closed their connection without logging off first. To get around this, follow the two command prompts below if you have rights. The easiest way to get rights is to map a drive with the administrator permissions.

query session /server:servername

This will provide you a list of  sessions. You should see sessions you can kill such as “rdp-tcp#1”.

reset session 2 /server:servername

This will kill the session associated with that ID which is found in the third column from your query command.

Installing ImageCR3 on 64-bit Multi-Instance ColdFusion Server

Update 2013-07-25: Efflare’s domain has expired and their 64-bit product never made it out of beta in years, so this is probably not the best solution to use anymore.

A client of mine uses ImageCR3 to manipulate images server-side. They moved to this a number of years back because at the time CFImage was crashing the server for them and we just haven’t spent the time to go back to it after a few upgrades.

This tag works great after you get it installed. Keyword being “after”.

On 32-bit servers it’s a fairly easy install and uses a C++ interface. However on 64-bit servers ColdFusion communicates with a Java Class.

Here’s the steps I needed to take to finally get this thing working after a few hours of fiddling around with it all. This is for a 64-bit multi-instance ColdFusion install.

  1. Stop all ColdFusion instances
  2. Run the install (my file is cfx_imagecr_3_service_beta_081030.exe)
  3. Install to the path of C:\Efflare\ImageCR3Service (do not install to “Program Files (x86))
  4. Edit the jvm_[instance name].config file in C:\JRun4\bin
    1. Add the following paths to the java.class.path variable
      1. {application.home}/servers/[instance name]/cfusion.ear/cfusion.war/WEB-INF/lib
        1. The reason this is added is due to a “java.lang.NoClassDefFoundError: com/allaire/cfx/CustomTag” error I was getting
        2. Verify that it is either cfusion.ear and cfusion.war or cfusion-ear and cfusion-war
      2. C:/Efflare/ImageCR3Service/imagecr3.jar
  5. In the CF Administrator add a Java CFX Tag named “cfx_imagecr3” with a class name of “ImageCR3” (case sensitive)
  6. Start the ColdFusion Instances
  7. Start the Efflare ImageCR3 Service
    1. If you miss this step you will get a “A network error occurred.” error

Hopefully this guide will help you save a few hours.

Installing ColdFusion on IIS 7

If you install a ColdFusion server under IIS 7 with default options, which is included with Windows 7, you will probably get a 500 error and less hair on your head.

The problem lies with a few IIS options you need to install.

For Windows 7:

  1. Uninstall ColdFusion if you already have it installed
  2. Open Control Panel > Programs
  3. Select “Turn Windows features on or off”
  4. If “Internet Information Service” is not checked, then check it
  5. Check “IIS Metabase and IIS 6 configuration compatibility” under “Web Management Tools” > “IIS 6 Management Compatibility”
  6. Check “ISAPI Extensions” under “World Wide Web Services” > “Application Development Features”
  7. Select “OK” to install these features
  8. Install ColdFusion