ColdFusion Builder extensions - Assigning multiple handlers to one file

This post is more than 2 years old.

Did you know there was a Google group dedicated to writing extensions with ColdFusion Builder? You can find it here. Earlier today Dave Ferguson asked an interesting question. He had an extension with a great number of actions. However, all these actions really just needed to run one particular ColdFusion file. Let's take a look at what he tried first and what a good possible fix could be.

His first attempt/thought was something like this:

<handler id="test1" type="CFM" filename="test.cfm?x=1" /> <handler id="test2" type="CFM" filename="test.cfm?x=2" /> <handler id="test3" type="CFM" filename="test.cfm?x=3" />

Basically - 3 different commands all running one CFM file but passing a URL variable to indicate which type of action should be run. Unfortunately this doesn't work at all. When I tried this the extension said no response was returned.

So what would I recommend? Make use of onMissingTemplate. Consider this example - first - the XML I used in the ide_config.xml file:

<handler id="test1" type="CFM" filename="test2.cfm" /> <handler id="test2" type="CFM" filename="test3.cfm" /> <handler id="test3" type="CFM" filename="test4.cfm" />

None of these files exist. In my Application.cfc I then used:

public boolean function onMissingTemplate(string targetpage) { request.requested = arguments.targetpage; include "test.cfm"; return true; }

All my code here does is take the requested template and store it into the Request scope. Using "requested" as a key in the Request scope may be a bit confusing, but, whatever. I then include the primary CFM that will handle all the requests. Your code could then do whatever it needs to based on the request variable.

Raymond Camden's Picture

About Raymond Camden

Raymond is a senior developer evangelist for Adobe. He focuses on document services, JavaScript, and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA

Archived Comments

Comment 1 by Dave Ferguson posted on 3/8/2011 at 6:38 AM

Great suggestion in getting around this issue. The only change I would make is this:

<cfset request.requested = ListFirst(ListLast(arguments.targetpage, "/"), ".")>

From what I have seen targetpage contains the full path to the template. This modification just gets the template name minus extension from the string.

Comment 2 by Raymond Camden posted on 3/9/2011 at 5:56 AM

Yep, and makes your code a bit simpler if you have a set of CFIFs. Ie,

<cfif action is "run">

instead of

<cfif action is "run.cfm">

Comment 3 by Dave Ferguson posted on 3/12/2011 at 8:22 PM

For this interested, I used this technique to create this extension.. http://jqmobilehelper.riafo...