blog | bio | agenda | jobs | ajaxCFC

ajaxCFC: addressing html code in application.cfc

I just got hit with an email informing me that ajaxCFC will break when application.cfc adds code onRequest(start|end). I modified the framework to reset the content before the JavaScript response, and abort it at the end of the asynchronous call. I am not quite happy with the abort though, so if someone has a better solution to eliminate all code generated by onRequestEnd please comment it here. I tried to open a JS comment segment, but then it results on unfinished comment; setting enable cfoutput only will only work if the code in application doesn't use cfoutput; cfsilent needs an ending tag.

The abort works for most of the cases; the AJAX request will always work, but if you had some custom code in your onRequestEnd, such as logging, it will not be executed.

Note on application.cfc: as a general rule, try to avoid using application.cfm/cfc for html rendering. It is advisable to separate your logic from the presentation layer. Application.cfc, just like any other component, is encapsulated and parameterized, and should not display html. If you successfully separate your logic from your views, you will be able to use the same architecture for presentation layers such as html, ajax, flash, flex, laslo, or mobile devices.

TrackBacks
There are no trackbacks for this entry.

Trackback URL for this entry:
http://www.robgonda.com/blog/trackback.cfm?C6803F76-3048-7431-E483E3DFF63CACD3

Comments
My opinion offered here. I don't believe the CFABORT is necessary. In fact, I believe it is a hindrance for probably 90% or more of developers out there.

I don't think you should put this band-aid solution in your code simply to accomodate a few people who have designed their application poorly.
# Posted By Steve | 1/16/06 2:51 PM
Steve, you are absolutely right; however, I decided to leave it as an option because the person have this problem has a valid point: he took the example straight out of Forta / Camden's book. I am sure they had the best intentions writing it and they will never do that on their own work, but if that inspires new CF programmers to adopt that methodology I would like to at least provide some support.
# Posted By Rob Gonda | 1/16/06 8:46 PM
In my previous post I forgot to mention what I did ... By default ajax.cfc will not abort after any request, but it is possible to enable is through the setAbortAfterRequest setter. Just add the function setAbortAfterRequest(true) in your ajax façade and it will force the request to be aborted before the onRequestEnd code runs.
# Posted By Rob Gonda | 1/16/06 8:48 PM
Ah, ok then that's cool. The original post just made it sound like it was an automatic function that was necessary. Forget my objections then :)
# Posted By Steve | 1/18/06 4:03 PM
Fear not, Steve. I originally (for an hour) made it required, but thanks to you reinforcing my objection to do it, I made it optional and disabled by default.
# Posted By Rob Gonda | 1/18/06 4:20 PM
Hi how are you *naf plz
# Posted By toto | 12/17/07 9:39 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.1.004.