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

How to use the APP_INITIALIZER token to hook into the Angular bootstrap process

I've been building applications using Angular as a framework of choice for more than a year and this post is not about another React vs Angular or the quirks of each framework. Honestly, I like Angular and every day I discover something new which makes development easier and makes me look like a guy who built something very complex in a matter of hours which would've taken a long time to put the correct architecture in place if I had chosen a different framework. The first thing that I learned in Angular is the use of the APP_INITIALIZER token.

Using MobX to manage application state in a React application

I have been writing applications using React and Redux for quite some time now and thought of trying other state management solutions out there. It's not that I have faced any issues with Redux; however, I wanted to explore other approaches to state management. I recently came across MobX  and thought of giving it a try. The library uses the premise of  `Observables` to tie the application state with the view layer (React). It's also an implementation of the Flux pattern wherein it uses multiple stores to save the application state; each store referring to a particular entity. Redux, on the other hand, uses a single store with top-level state variables referring to various entities.

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...