Skip to main content

ColdFusion 10: onAbort and onRequestEnd behavior

Today, I wrote a post on the new lifecycle method - ‘onAbort’, which can be defined in an Applicaiton.cfc file. It is invoked when the cfabort tag is executed. David Boyer, asked me whether the onRequestEnd method is also invoked on executing the cfabort tag. In CF 9.0.1 it did invoke the onRequestEnd method. See Ben’s post: http://www.bennadel.com/blog/2221-CFAbort-And-OnRequestEnd-Behavior-In-ColdFusion-8-And-ColdFusion-9.htm
Now in CF 10, this behavior has changed. The onRequestEnd method is no longer invoked when cfabort, cflocation or cfcontent tag is executed. The onAbort handler method defined in Application.cfc file would be invoked on executing these tags. Also, the onRequestEnd method would not be invoked even if the abort handler(onAbort) is not defined in Application.cfc.

Comments

  1. I'm pleased to hear that the abort / onRequestEnd behaviour was rolled back :) 

    What's the use case for firing the onAbort even handler when using cflocation or cfcontent though? The intent of the cflocation and cfcontent tags are nothing like doing an abort, IMO, so firing the same event handler for those tags / functions seems strange. 

    Even if the documentation is very clear about when this method is fired, I think it'll catch a lot of developers out because it's probably not what you'd expect to happen. This is why the whole abort / onRequestEnd things was so confusing in the first place!

    ReplyDelete
  2. When cflocation or cfcontent tag is used, the current request is stopped and hence the onAbort handler is invoked. In CF9, it invoked the onRequestEnd method in both the cases. Now such requests are handled through onAbort handler.

    ReplyDelete
  3. My question then, in concrete terms I guess, is *why* does onAbort fire when cflocation or cfcontent is used?

    The documentation says: "Runs when you execute the tag cfabort."
    http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSe61e35da8d318518-2bee337913585ea6004-8000.html 

    That seems perfectly fine if the documentation is accurate, but you're saying it will also run after cflocation or cfcontent...

    The documentation also says onAbort is only passed 1 argument, "targetPage". How can I use that to tell if a cfabort was executed, vs a cflocation or cfcontent? If I had some code that I wanted to handle cfabort's with, it would also be run every time a cflocation or cfcontent was executed - but I might not want that :)

    ReplyDelete
  4. w.r.t the documentation, I'll ask the doc team to update it. Log a doc bug for this.

    As of now, there is no way to determine whether the onAbort method was invoked for cfbort\cflocation\cfcontent. But, that was the same with onRequestEnd as well. However, I do see that, this information could come handy while debugging applications. Please log an ER for this, we will evaluate it.

    The reason why onAbort is invoked for cflocation and cfcontent is that the request terminates when one these tags is executed. Previously it was used to invoke onRequestEnd and now it is onAbort method. If the request would have completed gracefully then the onRequestEnd method would be invoked. This is not the case with cflocation or cfcontent and hence the change. I hope it makes sense now.

    ReplyDelete

Post a Comment

Popular posts from this blog

File upload and Progress events with HTML5 XmlHttpRequest Level 2

The XmlHttpRequest Level 2 specification adds several enhancements to the XmlHttpRequest object. Last week I had blogged about cross-origin-requests and how it is different from Flash\Silverlight's approach .  With Level 2 specification one can upload the file to the server by passing the file object to the send method. In this post I'll try to explore uploading file using XmlHttpRequest 2 in conjunction with the progress events. I'll also provide a description on the new HTML5 tag -  progress which can be updated while the file is being uploaded to the server. And of course, some ColdFusion code that will show how the file is accepted and stored on the server directory.

Server sent events with HTML5 and ColdFusion

There are several ways to interact with the server apart from the traditional request\response and refresh all protocol. They are polling, long polling, Ajax and Websockets ( pusherapp ). Of all these Ajax and Websockets have been very popular. There is another way to interact with the server such that the server can send notifications to the client using Server Sent Events (SSE) . SSE is a part of HTML5 spec:  http://dev.w3.org/html5/eventsource/

Adding beforeRender and afterRender functions to a Backbone View

I was working on a Backbone application that updated the DOM when a response was received from the server. In a Backbone View, the initialize method would perform some operations and then call the render method to update the view. This worked fine, however there was scenario where in I wanted to perform some tasks before and after rendering the view. This can be considered as firing an event before and after the function had completed its execution. I found a very simple way to do this with Underscore's wrap method.