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.
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.
I'm pleased to hear that the abort / onRequestEnd behaviour was rolled back :)
ReplyDeleteWhat'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!
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.
ReplyDeleteMy question then, in concrete terms I guess, is *why* does onAbort fire when cflocation or cfcontent is used?
ReplyDeleteThe 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 :)
w.r.t the documentation, I'll ask the doc team to update it. Log a doc bug for this.
ReplyDeleteAs 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.