Maybe Building The View Last IS The Best Way To Go

Posted July 25, 2007 at 2:20 PM by Ben Nadel

Tags: Work

I have always been hesitant to try out frameworks like ModelGlue and FuseBox where views are constructed once all the page data has been compiled. I just felt weird about that technique and thought that it was less than optimal in terms of unnecessary data processing. But, as of late, I am feeling like maybe this really is the best choice. What I do like about it is that it truly does divorce the display from the business logic. Now that I am spending a lot of time redesigning the look and feel of a few client sites, I am really feeling the effects of heavily coupled display-logic tiers.

One of the things I have always been concerned about is keeping the ability to use CFFlush. I am adamant about this. Not being able to flush a partial interface to the browser is simply not cool - call it a gut feeling, it's just how it has to be. What I am realizing though, is that blocking CFFlush is really a function of ColdFusion custom tags, not of the page-last rendering. After I compile my data, I can still partiall render my view, then flush to the client, then continue to render my view. I just have to be sure not to use any sort of ColdFusion custom tags for page wrappers (or anything that I might want to call CFFlush in the midst of).

So far, this has been a good year for me and programming epiphanies... and this might just be another one.




Reader Comments

Jul 25, 2007 at 2:45 PM // reply »
10,638 Comments

You know, I just had some time to reflect up on my above post and I am feeling that maybe I am to this already to some degree. I run my queries in separate files, I have my form validation in separate files (usually on the file that does the queries also).... my views are sort of divorced from my data compilation.

So, what is it that I am feeling. What is the design flaw that I am battling with right now????

Sorry, this is really stream of consciousness right now :)


Jul 25, 2007 at 3:22 PM // reply »
160 Comments

@Ben:

One thing to keep in mind about CFFLUSH...

If you're using IIS6's native GZIP to compress output, CFFLUSH will have no affect on the client. This is because IIS will wait for the entire page to process so it can GZIP it and send it to the customer.

(I know this doesn't really have anything to do with your blog, other than it's a CFFLUSH fact I don't think most developers are aware of.)


Jul 25, 2007 at 3:40 PM // reply »
12 Comments

I've never been able to use ModelGlue or fusebox, mostly because I'm stuborn and I like to do things my way (even if their way is almost completely the same, sometimes it just the little things I can't stand)

With CF8, I've finally made a nice "framework" of my own. You probably wont like it, since you cant CFFlush at all, and I'm sure its a bit slower than others, but it has some theoretical awesomeness that I love.

Suppose we're accessing index.cfm

onRequestStart creates an object called REQUEST.Page.

index.cfm:

The page object loads a layout from an xml file.
It's a real simple file, like this:

<page>
<widget id="head" />
<body>
<widget id="header" />
<widget id="content" />
<widget id="footer" />
</body>
</page>

Then, I create/save my content as xml, and all I insert them as nodes into the widgets in the layout. (The head, header, footer widgets are just outputs from various other objects)

So, now all my content is in an xml document, in a mix of html and my own custom tags.

in onRequest, after including index.cfm, I xmltransform it with my special xsl file, and I get a wonderful XHTML document (that I send as plain html).

What I like about this is that I'm able to make lots of presentational changes quickly, and it's really easy to adapt to new mediums (like mobile, or displaying things as pdfs), just be using a different xsl file.


Jul 25, 2007 at 3:52 PM // reply »
111 Comments

@Matt, I've seen a number of people doing site templating using XML XSLT (not much in the CF world). I remember some time back doing due diligence on a web agency that had a system doing just that. It's a really popular approach. Only issue I really have with it is that it doesn't allow less technical graphics types to make tweaks to layout so it increases the skill level (and hence cost) of tweaking a layout.


Jul 25, 2007 at 4:52 PM // reply »
10,638 Comments

@Dan,

You are right, in that I had no idea about that I had no idea re: the GZIP stuff in IIS. Funky.

@Matt,

I think that is cool, definitely lots of theoretical goodness. I actually used to work with a guy who did the same thing - creating every page as an XML document of some sort and then using XSLT. He did it in PHP and his pages were wicked fast.

@Pete,

I am sure Pete will have more to say about XML-based layouts in the future (Mwaa ha ha ha ha).


Jul 25, 2007 at 5:08 PM // reply »
12 Comments

That is a good point, although since I work alone, it isn't that critical to me.

Also, in my case, I design things incrementally, and I want each stage to be readable. This would make it possible to hire a graphics guy that only did css.

First I work with ColdFusion until I have an xml file that defines all my content (and I think is very readable)

Then, I work on my XML transform, until I have an html file that is useable without CSS.

Then I write the CSS, and hopefully everything looks perfect.


Jul 25, 2007 at 11:07 PM // reply »
2 Comments

Being a complete begginer in Coldfusion, I am working with a shopping cart written in CF and Fusebox 3.
I was not sure if this would be the best way to learn CF, but I must say the MVC seperation has certainly allowed me to understand at allot quicker rate than I expected. I find it easier to understand and less visually intimidating to look at and learn from a small piece of the larger picture at a time.
I can only assume that writing small reusable modules would be quicker.


Jul 26, 2007 at 12:56 PM // reply »
2 Comments

I don't miss the days of designing sites with separate header and footer files. That was awful.

Not being able to use CFFLUSH in those rare cases that I needed it was the one drawback. I'm not sure if any of the frameworks allow you to bypass the layout mechanism, but I lobbied for it in FB3.

Anyway, with the advent of AJAX, that's no longer an issue.


Jul 26, 2007 at 12:58 PM // reply »
10,638 Comments

@Patrick,

I think it wouldn't be too easy to take the ideas created in the major frameworks and allow CFFlush. It's probably just a design decision somewhere. I am gonna see what I can come up with. Gotta go examine the other guys, see how they do things.


Jul 26, 2007 at 4:42 PM // reply »
2 Comments

You could get FB3 to work with CFFLUSH if you took out nested layouts. Of course, that's like throwing the baby out with the bathwater. But there were a few cases where the ability to use CFFLUSH was more important than nested layouts. Theoretically, the framework could have been modified to bypass cfsavecontent and nested layouts on a case by case basis (by manipulating an API variable in the top level fbx_settings file).

You could then turn off cfsavecontent for individual fuseactions, or when a URL parameter is passed, for example.

I vaguely remember FuseQ/FB4 being advertised as working with CFFLUSH. I think it even supported nested layouts in the same request. You just couldn't have a top-level, master layout that contained both the opening and closing html tags.


Jul 29, 2007 at 4:57 PM // reply »
5 Comments

FB5 allows CFFlush to be used in a much more integrated fashion than FB3 (not sure about FB4.x as we skipped a generation)

cfflush can not be used with cfsaveconetent.

FB5 allows savecontent to be used on a per view or per action controlled by the controller. It does not enforce this.

Therefore something like the following would be possible:

include header view (maybe using cfflush)
do model stuff
include view (maybe using cfflush)
include footer view

..without using content variables at all.

We have used a technique like this in a couple of places where we needed this functionality. Its not as nice as using layouts - esp. as it seems to lead to having presentation layer code (cfflush) interspersed amongst the model code (as its normally the model stuff that will be taking time to process and need to be providing feedback to client)


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 3, 2012 at 10:49 PM
How I Got Node.js Running On A Linux Micro Instance Using Amazon EC2
Wow this was really helpful! Only thing I would add is you need to update your .bash_profile after you edit the secure_path. This is what I did: $ . ~/.bash_profile Otherwise, NPM won't be found. ... read »
Feb 3, 2012 at 10:14 PM
Pushing Base64-Encoded Images Over HTML5 WebSockets With Pusher And ColdFusion
@Ben, Just wanted to let you know that pusher are soon to start limiting sizes on messages. This was the detail that came through in the Feb dispatch: "However, we will soon be limiting the s ... read »
Feb 3, 2012 at 5:05 PM
Regular Expressions Make CSV Parsing In ColdFusion So Much Easier (And Faster)
I tried using your RegEx in my C# program, but it was matching an extra empty-string at the end and so I would end up with an extra field that doesn't exist, so I changed it to this: (^|,)("(?: ... read »
Feb 3, 2012 at 3:47 PM
ColdFusion Supports HTTP Verbs PUT And DELETE (As Well As GET And POST)
Josh Cyr posted this on Twitter just a little bit ago. Thought it was appropriate. http://stackoverflow.com/questions/1619152/how-to-create-rest-urls-without-verbs/1619677#1619677 ... read »
Feb 3, 2012 at 2:28 PM
Changing The Execution Context Of Your Self-Executing Function Blocks In JavaScript
@Michael, You definitely make a good point (and extra points for quoting movies - I love movies). When you use a return() statement to define the object's public API, it does provide a consistent a ... read »
Feb 3, 2012 at 2:04 PM
Changing The Execution Context Of Your Self-Executing Function Blocks In JavaScript
To quote Jurassic Park: "Just because you can doesn't mean you should". I completely, utterly disagree with the thought that this is more readable. Consider the current module pattern: if ... read »
Feb 3, 2012 at 1:10 PM
REST API Design Rulebook By Mark Masse
@Jordan, Yeah, WRML was created by Mark Masse (author of the book). I also found it to be a bit convoluted. I suppose it is intended to allow the Client to be able to programmaticaly respond to cha ... read »
Feb 3, 2012 at 1:08 PM
ColdFusion Supports HTTP Verbs PUT And DELETE (As Well As GET And POST)
@Jason, To be honest, I don't have good answers for that kinds of stuff. And, to the point, that is specifically why I *really* liked the REST API Design Rulebook by Mark Masse - he just cuts throu ... read »