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

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.

De-obfuscating javascript code in Chrome Developer Tools

I had blogged about JavaScript debugging with Chrome Developer Tools  some time back, wherein I have explained how these developer tools can help in debugging javascript code. Today Google Chrome 12 was released and my Chrome browser was updated to this version. As with every release, there have been some improvements made on performance, usability etc,. One feature that stood out for me is the ability to De-obfuscate the javascript code. What is Minification? Minification is the process of removing unnecessary characters such as white spaces, comments, new lines from the source code. These otherwise would be added to make the code more readable. Minifying the source code helps in reducing the file size and thereby reducing the time taken to download the file. This is the reason why most of the popular javascript libraries such as jQuery are minified. A minified jQuery file is of 31 KB in size where as an uncompressed one is about 229 KB. Unfortunately, debugging minified javascript f

On GraphQL and building an application using React Apollo

When I visualize building an application, I would think of using React and Redux on the front-end which talks to a set of RESTful services built with Node and Hapi (or Express). However, over a period of time, I've realized that this approach does not scale well when you add new features to the front-end. For example, consider a page that displays user information along with courses that a user has enrolled in. At a later point, you decide to add a section that displays popular book titles that one can view and purchase. If every entity is considered as a microservice then to get data from three different microservices would require three http  requests to be sent by the front-end app. The performance of the app would degrade with the increase in the number of http requests. I read about GraphQL and knew that it is an ideal way of building an app and I need not look forward to anything else. The GraphQL layer can be viewed as a facade which sits on top of your RESTful services o