Per request debugging in Model-Glue

A few weeks ago I spoke about how I use AJAX with Model-Glue. A reader, Jan Jannek, asked how she could use debugging without it breaking the XML results being returned by Model-Glue. Before I even had a chance to find the answer, she was able to dig it up:

I just found out by having a look at the MG-Examples of ajaxCFC, that there is the option to get rid of the debugging for a single event by adding:

<cfset request.modelGlueSuppressDebugging = true />

to the xml.view.cfm and everything works fine!

I confirmed this and it worked well. However - a note. Let's say you want to turn on debugging, but hide it by default. If you pass in a URL variable you would then want the debugging information to show up. This would be a bad idea for production, but during testing it would let you quickly see debugging information on a per request basis. This is possible, but you should be aware that Model-Glue does not actually check the value of request.modelGlueSupressDebugging. The mere existence of the variable will turn of debugging. Here is a simple way to add this functionality:

<cfset request.modelGlueSuppressDebugging = true />
<cfif structKeyExists(url, "showdebug")>
   <cfset structDelete(request, "modelGlueSuppressDebugging")>
</cfif>

This code simply looks for "showdebug" in the query string and if it exists, it removes the request variable instead of simply setting it to false. (This should be added to your application.cfm file of course.)

Comments

Although I haven't done any testing with AJAX-specific code, I have found that any JavaScript will break in Model Glue if you have debugging (and "Report Execution Times ") turned on. Turn off Report Execution Times and things start working.

One of the internal Model Glue methods (ViewRender?) will show up in the template list, thus duplicating the contents of the view on the page. How does JavaScript know which named element you are accessing when it exists twice? It doesn't.

This is one of the issue I cover in an upcoming article for FAQU.
# Posted By Jeff Houser | 9/18/06 9:30 AM
I should have been clear that I was speaking of MG debugging, not CF debugging. But you can turn off CF debugging on a per request basis as well.
# Posted By Raymond Camden | 9/18/06 9:33 AM
It may help if I mention the actual code in case folks don't know. To turn off debugging in CF on a request basis, use:

&lt;cfsetting showDebugOutput="false"&gt;
# Posted By Raymond Camden | 9/18/06 9:37 AM
I'm a victim of not reading too closely. ;)
# Posted By Jeff Houser | 9/18/06 9:50 AM
No - your point is definitely valid and would also screw up AJAX calls, so thanks for bringing it up. :)
# Posted By Raymond Camden | 9/18/06 9:56 AM
Ray, it is very important to note that turning off debugging per request like you mention does not remove or even reduce the performance hit you take with things like Model-Glue, Reactor or other frameworks. The debugging still runs as usual, only the output is suppressed.
# Posted By Brian Rinaldi | 9/18/06 11:41 AM
I did say you should not do this in production, but I didn't make it clear why. Thanks Brian.
# Posted By Raymond Camden | 9/18/06 1:18 PM