Model-Glue application walk-through

Once again Raymond Camden is putting every other ColdFusion developer to shame. He started a new blog series titled "Building your first Model-Glue application." It will be a step-by-step walk through of creating a Model-Glue app. If you've never used a ColdFusion framework (you're still writing spaghetti code, aren't you!), then this blog series may help you get introduced to the framework world. I have used Model Glue on one production website and have dabbled with it for a while now, and I think it is great, especially when combined with Doug's Reactor.

Reactor is Awesome!

I listened in on Doug Hughes' preso on Reactor at yesterday's Online ColdFusion Meetup Group. If you missed, visit the meetup site and listen in to the archived version.

<aside>I missed winning the ColdFusion 7 Standard Edition in the giveway by one person (random number selection from list of attendees) -- I was "sitting" right by the winner!</aside>

I had started using Reactor for my latest project while digging into ColdFusion OOP at the same time. The preso was quite good, but the best part was signing up for the Reactor mailing list afterward. I had a problem with the app I was creating when trying to join some tables to get all records--I didn't know how to use the Reactor objects to do the join and didn't know the "best practice" for doing it either. To make a long story short, you can create a function in the table's Gateway object (that is automagically created by Reactor) that create a Reactor query, joins tables, and can even set a where clause to grab the first record from a hasMany join. Here is an example of how to do that:

<cffunction name="getAllWithJoin" output="false" returntype="query">
<cfset var Query = createQuery() />
<!--- join all the associated tables --->
<cfset Query.join("Foo", "FooBar").join("Foo", "FooBee").join("Foo", "FooBoo")/>
<!--- only get first record from the table with the hasMany relationship --->
<cfset Query.getWhere().isEqual("FooBoo", "myField", 1) />
<!--- return the query --->
<cfreturn getByQuery(Query) />
</cffunction>

Easy as pie and database-independent too! Reactor is awesome--check it out!

Model-Glue redirects

As I'm working on this application (my first real Model-Glue app), I find myself referring to several different sources for examples and reference. In Doug Hughes' blog app, he did a simple event result tag after a form submission to display a list of foo objects. Well, if the user (me!) hit refresh, it would add another record. After asking about this on the MG mailing list, Doug suggested adding the "redirect" attribute to the result tag. I added it, but in one instance I needed to pass the foo id for displaying the view, so I started looking for how to do that. Well, I consulted the MG documentation, I mean QuickStart. What amazed me is this attribute is exactly what Joe Rinehart suggested--somehow I missed that the first twenty times I read through the doc! In addition, if you need to pass additional parameters, you need to use the "append" attribute with a list of keys from the state collection.

In order to make this rambling a bit more concrete, I modified this:

<result do="ListFooBar" />
to
<result do="ListFooBar" redirect="true" append="fooBarId" />

Now back to working on my app...

Making OOP headway (thanks Doug Hughes!)

Whether or not Doug Hughes knows it or not, he is now my hero. My mind has been swirling around with ColdFusion components/frameworks with names like ARF, Tartan, ChiliBeans, Mach II, Fusebox, ColdSpring, CF on Wheels, and Reactor. I'm working on a new project and decided to take the plunge into the framework and OOP world. I've always had a fancy for Joe Rinehart's Model Glue since he introduced it last year. I had been through his quick start, creating a "hello world" app for the masses (ok, just for me). But I never had time to explore it more. I have used his ARF product actually in production--and that was great! It gave me a real taste for how these frameworks and components can really save time. Anyway, to keep from digressing more, I have been reading about Doug's Reactor project with great interest, especially since Doug noted recently that the latest release includes sample code. Well, Doug's sample code has been a godsend. His blog example uses his Reactor for ColdFusion code inside a Model-Glue application! Exactly what I needed! Between Doug's Reactor documentation, Joe's MG Quick-Start Guide, and Doug's Reactor Blog sample, I have been able to create the beginnings of the new application I am working on. I have much more to do on the app, but all the pieces are working at the moment. This has helped me start to get my head around OOP and frameworks. I do still have many questions (time to post of the CFC Dev list!), but I think I'm making progress. Thanks to Doug and Joe!

ColdFusion and OOP

In order to discuss ColdFusion and Object-Oriented Programming (or OOP), I feel a bit of an introduction is in order. First, my background is in procedural programming (actually I first programmed on a Commodore 64, but that's another story). When I went to college for my CIS degree, I studied Pascal and Cobol for the programming requirements. After college, I continued down this road by using Delphi (pascal-based) and dabbling a bit with Visual Basic. When I started with ColdFusion (version 4.0), I began writing with procedural spaghetti code.

In 2002, I started to turn the road a bit and began to learn java for a project at work. Obviously I approached it from a procedural point of view, so it was difficult to get my head around, though I muddled through. With the advent of CFCs, I started seeing users trying to apply OO principles to ColdFusion. Following that, ColdFusion frameworks matured and new ones have been introduced.

I love the idea and promise of OO. I love the idea and promise of frameworks. But I'm in a procedural world. The code I maintain is procedure. Sure, we've done a lot of modularization over the past year-and-a-half, but that only gets us half-way there.

So my question is--how do you start? How do you break out of the procedural mode and get into OO with ColdFusion? How do you decide which framework to use? How do you decide which developer "helper" pieces to use with that framework (e.g. ARF, Reactor, ColdSpring, CFWheels, etc.)? I'm ready to jump in, but am at the learning curve wall (or is that a canyon?) and can't quite seem to climb it.

Comments and suggestions are welcome! This is the heart of where I am at and what I hope to post on much more in the future.

CFUnited 2005 - Day 2 - post 2

Day two at the CFUnited 2005 ColdFusion conference is starting to wind down for me now. It was another great day! The highlight for me was an afternoon session by Hal Helms on Domain Model. I almost didn't go because I wasn't sure what the talk was about. After reviewing the slides, I booked to the session because it was exactly what I needed. I am interested in moving toward using a ColdFusion framework for new development and likely using OO prinicples at the same time. The domain model is the entity/object/model part of MVC. Hal's overview was great. Basically the domain model is a software description of real world objects, such as customers, products, orders, etc. Creating a domain model has little to do with the programming language or framework you are using, but rather just describing the entity with something such as a UML (Unified Modeling Language) tool. I have a lot to learn, but Hal certainly whet my appetite. Thanks Hal!

BlogCFC was created by Raymond Camden. This blog is running version 5.8.