ColdSpring: An answer to a problem you may not know you have

Over the last two years or so I’ve been working hard to really “get” object-oriented programming as it applies to ColdFusion development. Like a lot of ColdFusion developers that have been around a while, when I started trying to create applications using CFCs, I essentially had CFCs that were collections of UDFs. Before long, after talking with other developers that understood OO principles, I started making my CFCs more “object’y” as I learned more about those principles.

Along the way I naturally heard about various frameworks related to ColdFusion (Fusebox, Model-Glue, Mach-II, ColdSpring etc etc) but never gave them more than a passing glance as I was trying to cram a bunch of new concepts into my brain as it was and I just didn’t have the mental bandwidth to take on frameworks at the same time (however that has since changed and I’ve had a chance to work with Mach-II and Model-Glue). Eventually I got to the point where my applications used numerous objects and some of those objects required the services of other objects to do their jobs. That’s the point that I really began struggling with the effort involved in writing a good OO application. It took lots of lines of code to create an object, configure it simply to pass it into another object. Sound familiar? Maybe you’re at that point with your ColdFusion OO trek. If so, read on and I’ll introduce you to ColdSpring, a free dependency-injection framework (whoa there, stay with me, don’t let the buzzwords turn you off) that will make your life much easier.

Read More

Configuring ColdFusion applications on Tomcat with Apache web server

In my last post I mentioned that I had been toying around with using Tomcat as the only servlet container to deploy all my ColdFusion applications to, regardless of what ColdFusion engine you needed to use for a specific project. My goal in trying to get this working was actually 3-fold:

  1. Learn more about how standard JEE servlet containers worked and how to configure them
  2. Remove my dependence on JRun as it is not under active development any more
  3. Be able to have one central place to start/stop each application’s instance as I switch between client projects

So far, I’m 2 for 3 on those goals. What follows is a brief history of what I did in the current iteration, what works well and what I’m still missing to have what I believe is the perfect development environment (at least for my situation). The steps I took here are based on my experiments using Mac OS X, but should be fairly close for Windows users.

Read More

To .WAR or not to .WAR?

A week or so ago, Matt Woodward posted a blog entry detailing how to install Railo and Open BlueDragon on Tomcat. Since then I’ve been experimenting with installing not only Railo and Open BlueDragon into Tomcat, but Adobe ColdFusion 8 and MX 7 as well. I’m trying to determine if this configuration is better for me as a consultant that works on a variety of customer projects on various CFML engines. I’ll leave that discussion for a future post as I’ve not decided quite yet what I think.

One thing that this experimenting has me thinking a lot about, however, is the “organization” of the code base for our projects. Here’s the question that I’m working through in my head at the moment. Should we be organizing our application code so that it can be packaged up in a WAR file–whether or not we ever expect to deploy our application as a WAR? I realize that everyone has a different “pet” way they like to organize their project code–I myself have been using a certain standard folder structure that I like for a couple years now. However, my folder structure would not work if you wanted to take my application and package it up as a WAR file that included a specific CFML engine.

As an example, I have been including a /conf directory (for framework XML config files etc) in my project structure that is at the same level as my /html directory (this functions as my web root). Most of us have most likely heard people advocating this structure because it puts the XML files outside of the web root and thereby protects people from being able to browse our XML config files directly to view sensitive configuration data for our applications. This particular organization would break since the context root as defined in the WAR file needs to be the directory that includes my web files (/html in this case). So, I would need to reorganize my project so that any files that need to be deployed via the WAR file would reside under my /html folder.

I’m VERY new to the whole Java servlet container scene, and therefore I obviously don’t know what is possible in the Tomcat configuration files that might address this issue. I suppose it might be possible to use the configuration options in the web.xml or context.xml to modify your project structure, but right now I’m not familiar with how to get this accomplished.

What do most shops do when developing a new application that could be deployed on any given CFML engine? Should we be trying to use the standard Java WAR method or continue to use the methods we’ve all been using to now deploying individual files to a web root on a server?

I’m leaning toward rethinking my project organization to allow deployment via WAR files and using some sort of process in an Ant build script to include a specific runtime depending on what CFML engine is required for the project (or none at all if it is to be deployed as simply files under a web root). Any thoughts or suggestions?

Using Decorator objects in Transfer ORM

For the last few weeks I’ve been working on a project that uses the Mach II, ColdSpring and Transfer frameworks for ColdFusion. This is my first “real” project using Transfer and, I have to say, I’m supremely impressed with the thought and work put into the framework by Mark Mandel. It seems every time that I come up with a question of how to do something, a quick look at the methods provided in the objects generated by Transfer reveals the answer.

The latest example came this week as we were moving more heavily into coding from the planning stages we’d been in for the most part up to now when I had an occasion to use the decorator feature built into Transfer.

Read More

Interesting gotcha with nested loops in ColdFusion MX7

I am working on a project for a client that is running ColdFusion MX7 on their servers and ran into a situation today where a search feature that worked perfectly in my local development environment (which, admittedly is running CF 8) produced some very inconsistent results when run on the testing server.

This particular search has to combine results from not only two different databases, but two different database systems (MySQL and Oracle). In making this work, I had written queries to extract the required information from each database separately, then created a query-driven loop based on one of the queries that was nested inside a second query-driven loop based on the other.

The code I originally wrote was similar to what is below (the client-spefic parts of the original code have been removed).

1
2
3
4
5
6
7
8
9
10
<cfloop query="queryA">
   <cfloop query="queryB">
      <cfif queryA.someField EQ queryB.someField>
         <cfset foo = queryA.someOtherField>
         <cfset bar = queryB.someOtherField2>
         ...do some more stuff...
         <cfbreak>
      </cfif>
   </cfloop>
</cfloop>

This led to getting the correct number of rows generated on the “view” page, however all the rows displayed the same information (as if I had 175 rows of the exact same data) which was obviously wrong. After reading the last comment on this page on Adobe Livedocs, I updated the code to what is below and resolved the problem.

1
2
3
4
5
6
7
8
9
10
11
<cfloop query="queryA">
   <cfloop query="queryB">
      <cfif queryA.someField[queryA.currentRow] EQ 
             queryB.someField[queryB.currentRow]>
         <cfset foo = queryA.someOtherField[queryA.currentRow]>
         <cfset bar = queryB.someOtherField2[queryB.currentRow]>
         ...do some more stuff...
         <cfbreak>
      </cfif>
   </cfloop>
</cfloop>

It seems that in a nested loop configuration such as that, ColdFusion MX7 sometimes “forgets” where it is in each respective loop and that implicitly specifying the currentRow attribute of the query forces it back to its correct spot.

It took a while to nail down just what was causing the problem, but thankfully it was a pretty easy fix.