coldfusion cfinclude before and after callbacks - coldfusion

Is there any possibility to call some callback function for Debugging purpose before and after the cfinclude tag.
for example if i have
<cfinclude template="xyz.cfm" />
and is Logging is enabled, I would like to call abefoeInclude and afterInclude callbacks.
Is there a possibility to achive this?

You can create your own version of cfinclude as a custom tag http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=reuseCode_2.html
Inside that you can check if debugging is turned on using isDebugMode() and do your logging in side the custom tag. Then you can use the custom tag instead of cfinclude.
I hope that makes sense.

Do you mean whether debugging is enabled? You use the ColdFusion function isDebugMode().
http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7bf4.html

Related

Do custom tags in application.cfc ignore this.customTagPaths?

Within my root application.cfc I define this.customTagPaths. This is verified to work on all pages, including those in subfolders. Within one subfolder I have an application.cfc that extends this root application.cfc. Pages within this folder still use the correct custom tags so we know that this is working correctly.
However, when trying to use a custom tag within the [subfolder]/application.cfc file itself I believe it is pulling from a different custom tag path. I added some debug information into the custom tag and it outputs when the custom tag is called from a normal page, but does not output when called from the application.cfc. I do not have access to the server to put debugging information in the other custom tag paths to be sure.
Does code in the application.cfc ignore this.customTagPaths and, if so, how do I use the specific tag I need? This custom tag sets a variable in the caller scope, so it cannot be called with a simple cfInclude.
Edit
I will attempt to address some of the questions in the comments here.
The custom tag in question has been simplified down to this code:
<cfset Caller.groupList = "">
<cfquery name="getGroups">
SELECT id, name
FROM groups
WHERE id = 1
</cfquery>
<cfoutput query="getGroups">
<cfset Caller.groupList = #ListAppend(Caller.groupList, name)#>
</cfoutput>
<cfoutput>Caller.groupList: #Caller.groupList#<br></cfoutput>
The Application.cfc is using this code:
<cfcomponent extends="RootApplication">
............
<cf_groupList>
<cfoutput>request.groupList: #request.groupList#<br><br></cfoutput>
</cfcomponent>
When cf_groupList is called directly from a cfm it writes "Call.groupList: xxxx" out to the page and shows the correct values from the dev database. However, when the Application.cfc runs the custom tag "Call.groupList: xxxx" never appears, but "request.groupList: xxxx" does, and in the latter case it shows the list that we would expect from the live database. Both the live and dev sites are currently on the same server, which we are in the process of changing, but for now I have no debugging information.
The reason I am calling a custom tag from Application.cfc is because this tag is used many other places. Simply copying and pasting the code into Application.cfc would solve the problem, but then we have an issue of duplicated code that we need to remember to update in two places in the future. Using the custom tag in the application.cfc instead of duplicating code seemed like the correct approach.
Mark, you are correct. When placed in the parent Application.cfc the custom tag works correctly. In the child it does not.

ColdFusion IDE equivalent to Visual Studio's "go to definition" and "find usages"

Do any of the ColdFusion IDEs/IDE plugins allow you to perform actions similar to Visual Studio's go to definition and find usages (some details of which are on this page)?
For example, in one .cfc file I might have:
<cfset variables.fooResult = CreateObject(
"component",
"Components.com.company.myClass").fooMethod()>
And in myClass.cfc I have:
<cffunction name="fooMethod" access="public">
<!-- function body -->
</cffunction>
If I have my cursor set over .fooMethod in the first file, a go to definition action should place me on the declaration of that method in myClass.cfc.
At present I'm using the CFEclipse plugin for Eclipse to view some legacy ColdFusion.
CFEclipse doesn't have this functionality, partly because CFML is a dynamic language with a fair bit of complexity parsing-wise.
You can use regex searching to get you most of the way there in most cases.
Function Definitions
To find a function definition, most times searching for...
(name="|ion )methodname
...is enough, and quicker than the more thorough form of:
(<cffunction\s+name\s*=\s*['"]|\bfunction\s+)methodname
Function Calls
To find a function call, against just do:
methodname\s*\(
Though against you might need to be more thorough, with:
['"]methodname['"]\s*\]\s*\(
...if bracket notation has been used.
You might also want to check for cfinvoke usage:
<cfinvoke[^>]+?method\s*=\s*['"]methodname
Of course, neither of these methods will find if you have code that is:
<cfset meth = "methodname" />
<cfinvoke ... method="#meth#" />
...nor any other form of dynamic method names.
If you really need to be thorough and find all instances, it's probably best to search for the method name alone (or wrapped as \bmethodname\b), and manually walk through the code for any variables using it.
IF you use
<cfset c = new Components.com.company.myClass()>
<cfset variables.fooResult = c.fooMethod()>
I believe in CFBuilder you can click Ctrl and the CFC class and method will turn into a hyperlink. See "Code insight" on http://www.adobe.com/ca/products/coldfusion-builder/features.html It works when it work, it doesn't when mapping is incorrect or certain syntax may not be supported. I'm not sure if they support the CreateObject() way.
There's no find usage as CF is not a static language. However, the Find can find what you need most of the time unless the code invokes method dynamically or uses Evaulate()

Difference between cfc and cfm

I'm trying to create basically a library of UDFs (User Defined Functions) for a web site run in ColdFusion. While doing this I am trying to find out what the differences are between cfc and cfm files. Which would be more helpful in creating this library of functions? I know that I can use
<cfinclude template="mytemplate.cfm>
to include it in a page but that will run the entire contents of that cfm on that page every time. I don't know and easier way to use cfc other than to create an object of the cfc and call the function that way.
<cfobject type="component" action="create" name="test">
Any ideas?
The way that I do it is to create all my UDF in a cfc. I then initialize that cfc on application start:
public function onApplicationStart() {
// Application settings
application.util = createObject("component","cfc.util");
return;
}
use a cfc you can call more easily from more places, if its not too huge put it into your application scope

How can I have ColdFusion tags in a variable and have them evaluated?

I've get a variable that can contain a CF custom tag. E.g.
<cfset a = '<model:sparkline id="1"/>'/>
And I'd like that to be evaluated into HTML and outputted. Not sure how/if I can do this.
Can you modify the custom tag? If so you can use the caller scope to set a variable in the calling page. So inside the custom tag you could do <cfset caller.a = "whatever" /> and that will set the value in the calling page's variables scope.
If you don't want to modify the custom tag, then you can use <cfsavecontent> to save the output to a variable. Example:
<cfsavecontent variable="a">
<model:sparkline id="1" />
</cfsavecontent>
Sean Coyne's answer is the correct one, provided the import is included within the same context as the cfsavecontent tag:
<cfimport taglib="./tags" prefix="model">
<cfsavecontent variable="a">
<model:sparkline id="1" />
</cfsavecontent>
<cfoutput>#a#</cfoutput>
Will result in the dynamically evaluated output of the sparkline customtag.
It's impossible to OUTPUT the code and have it execute. OUTPUT just means output. It doesn't mean "run".
The only way to get CF code to be executed by CF is to follow normal channels:
* request a template;
* include a template;
* call a template as a custom tag or CFMODULE;
* call a method in a CFC;
* any others? ANyway, you get the point.
So if you have code that you create dynamically and want to execute... you need to write it to a file and then call it via the most appropriate of those mechanisms. Be warned though: running dynamic code like this has a fair overhead, as the code needs to be compiled before it's run, and compilation is not the fastest process in the scheme of things. The "best" thing to do here is to try to write and compile the file before it's needed, and only re-write the file it it needs updatng. Don't re-do it every request. But, ideally, don't do this sort of thing at all. One can usually approach things a different way.

Is there a way to use <cfhtmlhead> in cfscript?

I want to use <cfhtmlhead> in a full script component. But it appears that it has no <cfscript> equivalent.
The CFScript reference is available here.
Is there a work around to use this functionality in a full script CFC?
You would need to write a tag based version that is then included into the script based CFC. I've done this before for things like cfsetting.