Bug with Railo and OnMissingTemplate in Application.cfc

{ Posted By : Eric Cobb on February 9, 2009 }
2119 Views
Related Categories: Railo

Recently I was finishing up a CFML project that's going to be run on top of Railo. Since this particular project was a redesign of an existing site, maintaining search engine rankings was a big concern. Many of the files on the new site had been relocated or renamed, so I was planning on using the onMissingTemplate method in Application.cfc to redirect users (and search engines) to the new files based on what had been requested.

Imagine my surprise when I found that Railo doesn't seem to recognize onMissingTemplate!

Every time a call to a non-existing template was made, Railo called onError instead of onMissingTemplate. After a little research, I determined that this was a bug in Railo and I decided to try to code around it. A little more research led me to an excellent code work around for this issue. I wish I could remember where I found it, but it was buried deep in some Google results. (please feel free to comment below if you know who originally came up with this solution)

<cffunction name="OnError" access="public" returntype="void" output="true">
    <cfargument name="Exception" type="any" required="true" />
    <cfargument name="EventName" type="string" required="false" default="" />
        
    <!--- Railo calls OnError instead of OnMissingTemplate, we have to account for that here. --->
    <cfif structKeyExists(SERVER,"railo")>
        <!--- if it's a missing template error --->
        <cfif structKeyExists(ARGUMENTS.exception,"type") and ARGUMENTS.exception.type eq "missinginclude">
            <!--- pass it over to the onMissingTemplate method--->
            <cfset onMissingTemplate(targetPage=ARGUMENTS.exception.missingFileName_rel) />
            <cfelse>
                <cfdump var="#ARGUMENTS#" />
            </cfif>
        <cfelse>
            <cfdump var="#ARGUMENTS#" />
        </cfif>
        
        <cfreturn />
</cffunction>

The code is pretty simple, and this solution works nicely. Basically, when the onError method in Application.cfc is called it checks the server and the exception type to see if it's Railo and a missing template. If so, it calls onMissingTemplate and passes in the requested page name, then onMissingTemplate template does its thing. Please note, the code in the example is psudo code only and I have not tested it to verify it runs correctly.

But wait, there's more! I got everything implemented and put into production over the weekend. My onMissingTemplate method is called when it should be, and everything is working nicely. While I was working in the Railo administrator getting the site set up, I happened to check the Update link to see if there was anything I needed to add. Wouldn't you know it, one of the bug fixes listed in the latest update is "add support for onMissingTemplate to Application.cfc".

Just my luck...

Comments
Jim Connor's Gravatar I just downloaded the latest stable release yesterday (3.02.004) and onMissingMethod is still not being called. Do you know what version the bug fix is supposed to be in?
# Posted By Jim Connor | 4/2/09 8:46 AM
Jim Connor's Gravatar OK, I've come down off of my early morning caffeine buzz (mostly). We're on version 3.1.0.012-beta, and still no onMissingTemplate.
# Posted By Jim Connor | 4/2/09 9:07 AM
Eric Cobb's Gravatar @JIm - not sure if it will help you any, but I'm running version 3.0.2.001 final.
# Posted By Eric Cobb | 4/5/09 10:28 PM