Posts in Category "ColdFusion"

CFEclipse and Flex Builder 2: Happy Together

I now do all my Flash development in Flex Builder 2. No exceptions. But I still use another installation of Eclipse for other types of development (ColdFusion, Java, HTML, JavaScript, etc.). Yesterday, I ran into a situation where I needed to embed a small Flex application in a custom HTML page, so tried installing CFEclipse into Flex Builder 2, and it seems to work perfectly. It’s not guaranteed to work, and I supposed it could break in the future, but for now, I’m a very happy developer.

Update: I should qualify that I’m talking about the standalone version of Flex Builder 2. The plugin version will definitely work with CFEclipse.

Making Your ColdFusion and Java Applications More Platform Independent (Part III)

Making Your ColdFusion and Java Applications More Platform Independent (Part III)

Two years ago (has it really been that long?!), I made a couple of posts about how to make your ColdFusion and Java applications more platform independent. The first post covered the importance of case consistency, and the second talked about not hard-coding path separators since they are different on different platforms. Well, all this time later, I actually have a third piece of advice: don’t hard-code new line characters.

I’m switching my development environment over from OS X to Windows (I haven’t used Windows consistently in many years, so I figured it was time to give it a try again), and while trying to get MXNA running locally, I came across a bug that I’d never seen in development (on OS X) or on production (Linux). The problem was this line of code:

<cfset blArray = listToArray(blacklist, chr(10))/>

The code is trying to convert a line-separated list into an array. On OS X and Linux, it works fine since the new line character is "line feed", or chr(10), or \n, but on Windows, the code didn’t work because a new line is "line feed" and "carriage return", or chr(10) & chr(13), or \n and \r. So rather than ever having to worry about this again, I used a little Java trick to make the code run in any environment. Now it looks like this:

<cfset blArray = listToArray(blacklist, createObject("java", "java.lang.System").getProperty("line.separator"))/>

Even with a language like Java (and hence, ColdFusion), if you want your code to be truly platform independent, it takes a little work. The good news is that once that was fixed, MXNA was up and running in my development environment perfectly.

Why Distinguish Between GETs and POSTs?

It’s nice that ColdFusion gives you the option of distinguishing between GET and POST requests by putting variables in two different scopes (the “url” and “form” scopes, or structs), but with the framework I’ve put together for ColdFusion applications, I don’t really need to know. In fact, I don’t want my code distinguishing between the two because it makes it less generic (meaning I’m forced to make requests in way or the other). The answer has been to include this little piece of code from my Application.cfc file:

[code]

[/code]

Now I reference everything in the “request” scope or struct, regardless of whether it was submitted through a form or a URL parameter which makes my code more generic and reusable.

Don’t Forget to Scope CFHTTP

I ran into a nasty MXNA 2.0 bug last week. As many of you noticed, we had a case
where one person’s posts were attributed to someone else. I was stumped for about
an hour as I went through lots of lines of code, and long spells of staring into
space and contemplating. Then it hit me that since this has only happened one time
in all the thousands of posts MXNA 2.0 has aggregated, it must be a concurrency
issue.

And it was. MXNA 2.0 uses cached instances of parser components, and in one of
those components was a CFHTTP tag that wasn’t scoped, or "VARed". Just
the right sequence of events caused the variable cfhttp.fileContent to be overwritten
with a string from someone else’s feed. It’s a one in a million shot, but it happened
once, and it would have happened again given enough time.

If you’re using CFHTTP in a component, and you’re using CF 7.0, your code should
look like this:

<cfset var foo = 0/>
<cfhttp result="foo".../>

If you’re using CF 6.x, it should look like this:

<cfset var cfhttp.fileContent = 0/>
<cfhttp .../>

Note: I owe Sean Corfield a big thanks for helping me track this down.

xmlSearch is Always Case Sensitive

The ColdFusion function xmlSearch is always case sensitive, it seems, even if you specified case insensitive in the xmlParse function to create the XML object in the first place. So if you’re parsing an XML document that you don’t have complete control over (like an RSS feed), be careful. If there’s a chance the case could be different than what you’re expecting, make sure you search for both upper and lower case.

UTF8, MySQL 4.1, and CFMX 7.0

I spent a good portion of my day trying to get unicode to work with MySQL 4.1 and CFMX 7.0. As it turns out, it’s actually pretty easy. I had the database tables created correctly. That I learned from earlier versions of MySQL. Just add this to the end of your CREATE TABLE command:

CHARACTER SET utf8;

I even had the connection string right in the data source form in the CFMX administrator:

useUnicode=true&characterEncoding=UTF8

The problem is that the connection string apparently doesn’t go in the “connection string” field. Since I’m using a newer MySQL driver than the one that shipped with CFMX 7 (that supports MySQL 4.x), I discovered that you actually have to append the connection string to the JDBC URL, like this:

jdbc:mysql://localhost:3306/dataBaseName?useUnicode=true&characterEncoding=UTF8

Once I made the change, instant Japanese! I hope this saves someone out there several hours of head scratching.

Partial Page Caching with ColdFusion

ColdFusion Jedi Master Ray Camden will be giving a Macrochat on partial page caching
with ColdFusion tomorrow (Wednesday) from 1:00 to 2:00 Eastern. Here’s
the official stuff:

Learn how to write a custom tag that allows for simple caching in ColdFusion MX.
Ray Camden will lead this discussion on creating a CF tag for partial page caching
of information. Ray is the Director of Development for Mindseye, Inc., a Team Macromedia
member, and Macromedia User Group manager.

What You Will Learn

  • Existing ColdFusion Caching (query caching and cfcache)
  • Persistant Scopes
  • The ScopeCache Custom Tag

If you’re interested, you
must register
!

CFMX 7 in the News

Here are all the mentions of the CFMX 7 launch in the news that I’m aware of:

Props to Macromedia PR for digging up all these articles.

Macromedia ColdFusion 7.0 Resources

Everyone knows by now that Macromedia announced ColdFusion 7.0 today, so rather
than making an announcement that everyone has already heard, I thought I’d post
a few links to some good ColdFusion 7 resources that I’ve come across today:

Eliminate ColdFusion Whitespace Once and For All

Since I’m at Macworld this week, and consequently don’t have a lot of time to
put into my weblog, I’m going to be lazy, and reprint a comment that was sent to
me by Jon Alsbury. It was submitted in response to a post entitled Controlling
Whitespace in ColdFusion
. John writes:

The most effective (and easy to implement) technique for reducing whitespace in
CFMX generated pages I have discovered so far is to set up a simple servlet filter
to intercept the response in order to strip out whitespace before it is returned
to the client. The filer I’ve been using for this is called Trim Filter and can
be downloaded here:

http://www.servletsuite.com/servlets/trimflt.htm

Setup is easy: simply download trimflt.jar from the above URL, drop it into your
‘cfusionmx/lib’ directory. Add the following to ‘cfusionmx/wwwroot/WEB-INF/web.xml':

<filter>
<filter-name>trimFilter</filter-name>
<filter-class>com.cj.trim.trimFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>trimFilter</filter-name>
<url-pattern>*.cfm</url-pattern>
</filter-mapping>