Re: UDF within a Custom Tag
This thread got me thinking about my code in CFMX 6.1. If I have a cfscript-based UDF inside of a custom tag, and that function is only called in the executionmode=end block, is it a best-practice to declare that function in the end block, or does it not matter where the fuction is defined inside of the tag? I do not want CF to parse the same function twice, once for the start tag and once for the end tag, if it is only being used by the end tag. Thank you, Mike Chabot Jamie - If you are on CF5 you only have 2 choices really... Use the request scope. You would define the UDF in the request BEFORE you call the custom tag. Ie, Application.cfm may cfinclude a file of UDFs where each UDF is copied to the request scope. You would call the UDF in the CT by using request.foo() In the custom tag, use cfinclude to include the file only in executionMode = start. Both of those will work. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
UDF within a Custom Tag
I have had a problem a couple times when I've tried to put a UDF within a custom tag. CF insists that the function has been declared more than once. I figured this was because of the sort of doubling effect the start/end execution modes have, but the problem persists even when I have cfif thistag.executionmode is endcfexit method=exittag/cfif at the top of the custom tag. I think that when I've encountered this, I've had to remove the UDF, request-scope it, and put it in the general UDF library, even though it really is just a private method of the custom tag. Solutions? Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
RE: UDF within a Custom Tag
You are getting this error as by default Custom Tags are called twice internally AFAIK.. _ From: Jamie Jackson [mailto:[EMAIL PROTECTED] Sent: 21 July 2004 16:25 To: CF-Talk Subject: UDF within a Custom Tag I have had a problem a couple times when I've tried to put a UDF within a custom tag. CF insists that the function has been declared more than once. I figured this was because of the sort of doubling effect the start/end execution modes have, but the problem persists even when I have cfif thistag.executionmode is endcfexit method=exittag/cfif at the top of the custom tag. I think that when I've encountered this, I've had to remove the UDF, request-scope it, and put it in the general UDF library, even though it really is just a private method of the custom tag. Solutions? Thanks, Jamie _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
Are you still running 6.0? I believe they fixed this in 6.1. In 6.0 I resorted to either using request scoped vars or using code to cfinclude the UDF when executionmode=start. Also, if you just want the tag to run in start mode, you can simply put this at the end of your custom tag: cfexit method=EXITTAG No need to check execution mode. This one line will simply make the custom tag run in start mode. On Wed, 21 Jul 2004 11:25:25 -0400, Jamie Jackson [EMAIL PROTECTED] wrote: I have had a problem a couple times when I've tried to put a UDF within a custom tag. CF insists that the function has been declared more than once. I figured this was because of the sort of doubling effect the start/end execution modes have, but the problem persists even when I have cfif thistag.executionmode is endcfexit method=exittag/cfif at the top of the custom tag. I think that when I've encountered this, I've had to remove the UDF, request-scope it, and put it in the general UDF library, even though it really is just a private method of the custom tag. Solutions? Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 16:38:03 +0100, in cf-talk you wrote: You are getting this error as by default Custom Tags are called twice internally AFAIK.. So are UDFs not allowed within Custom Tags? I also tried wrapping the function declaration in a testing conditional: cfif not isdefined(doOption) cfscript function doOption() { ... } /cfscript /cfif But CF complains that doOption is a complex variable, and it can't test for its definition. Is there a way to do an existence test on UDFs, or is there a cleaner way to do UDFs in Custom Tags? Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
RE: UDF within a Custom Tag
Yeah...see Ray's comments...I skipped 6.0 out altogetheras it was way too unstable!Ray is the man he is Mr UDF ;-) _ From: Jamie Jackson [mailto:[EMAIL PROTECTED] Sent: 21 July 2004 16:52 To: CF-Talk Subject: Re: UDF within a Custom Tag On Wed, 21 Jul 2004 16:38:03 +0100, in cf-talk you wrote: You are getting this error as by default Custom Tags are called twice internally AFAIK.. So are UDFs not allowed within Custom Tags? I also tried wrapping the function declaration in a testing conditional: cfif not isdefined(doOption) cfscript function doOption() { .. } /cfscript /cfif But CF complains that doOption is a complex variable, and it can't test for its definition. Is there a way to do an existence test on UDFs, or is there a cleaner way to do UDFs in Custom Tags? Thanks, Jamie _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
I'd set a request-scoped variable just before or after my function declaration (ie request.functionnameIsDeclared or something else you'll never use anywhere else) and check for its existence. --Ben Jamie Jackson wrote: On Wed, 21 Jul 2004 16:38:03 +0100, in cf-talk you wrote: You are getting this error as by default Custom Tags are called twice internally AFAIK.. So are UDFs not allowed within Custom Tags? I also tried wrapping the function declaration in a testing conditional: cfif not isdefined(doOption) cfscript function doOption() { ... } /cfscript /cfif But CF complains that doOption is a complex variable, and it can't test for its definition. Is there a way to do an existence test on UDFs, or is there a cleaner way to do UDFs in Custom Tags? Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 10:45:21 -0500, Raymond Camden [EMAIL PROTECTED] wrote: Are you still running 6.0? I believe they fixed this in 6.1. Nope, running 6.1. Any ideas with that in mind? Might I be doing something wrong? In 6.0 I resorted to either using request scoped vars or using code to cfinclude the UDF when executionmode=start. Also, if you just want the tag to run in start mode, you can simply put this at the end of your custom tag: cfexit method=EXITTAG No need to check execution mode. This one line will simply make the custom tag run in start mode. Neat trick, thanks. I guess the only thing I don't like about it is it's kinda buried down there. Cleaner, though. On Wed, 21 Jul 2004 11:25:25 -0400, Jamie Jackson [EMAIL PROTECTED] wrote: I have had a problem a couple times when I've tried to put a UDF within a custom tag. CF insists that the function has been declared more than once. I figured this was because of the sort of doubling effect the start/end execution modes have, but the problem persists even when I have cfif thistag.executionmode is endcfexit method=exittag/cfif at the top of the custom tag. I think that when I've encountered this, I've had to remove the UDF, request-scope it, and put it in the general UDF library, even though it really is just a private method of the custom tag. Solutions? Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
This is not true. If you do cf_foo it will certainly NOT run twice. It will only run twice if youcf_foo / or cf_foo/cf_foo On Wed, 21 Jul 2004 16:38:03 +0100, Robertson-Ravo, Neil (RX) [EMAIL PROTECTED] wrote: You are getting this error as by default Custom Tags are called twice internally AFAIK.. _ From: Jamie Jackson [mailto:[EMAIL PROTECTED] Sent: 21 July 2004 16:25 To: CF-Talk Subject: UDF within a Custom Tag I have had a problem a couple times when I've tried to put a UDF within a custom tag. CF insists that the function has been declared more than once. I figured this was because of the sort of doubling effect the start/end execution modes have, but the problem persists even when I have cfif thistag.executionmode is endcfexit method=exittag/cfif at the top of the custom tag. I think that when I've encountered this, I've had to remove the UDF, request-scope it, and put it in the general UDF library, even though it really is just a private method of the custom tag. Solutions? Thanks, Jamie _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 12:00:48 -0400, Ben Doom [EMAIL PROTECTED] wrote: I'd set a request-scoped variable just before or after my function declaration (ie request.functionnameIsDeclared or something else you'll never use anywhere else) and check for its existence. --Ben Doh! Why didn't I think of that? :) It's a teeny bit tedious to have to do this, but it's better than moving the private UDF elsewhere. Thanks! Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 12:11:13 -0400, in cf-talk you wrote: On Wed, 21 Jul 2004 10:45:21 -0500, Raymond Camden [EMAIL PROTECTED] wrote: Are you still running 6.0? I believe they fixed this in 6.1. Nope, running 6.1. Any ideas with that in mind? Might I be doing something wrong? Whoops, I forgot for a moment which environment this app's in. Our CFMX boxes are all 6.1, but this old site happens to be on _CF5_, not MX at all. Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
RE: UDF within a Custom Tag
Yeah, sorry ray...I just seen Tag Execution but and whacked on the keyboard ;-) _ From: Raymond Camden [mailto:[EMAIL PROTECTED] Sent: 21 July 2004 17:12 To: CF-Talk Subject: Re: UDF within a Custom Tag This is not true. If you do cf_foo it will certainly NOT run twice. It will only run twice if youcf_foo / or cf_foo/cf_foo On Wed, 21 Jul 2004 16:38:03 +0100, Robertson-Ravo, Neil (RX) [EMAIL PROTECTED] wrote: You are getting this error as by default Custom Tags are called twice internally AFAIK.. _ From: Jamie Jackson [mailto:[EMAIL PROTECTED] Sent: 21 July 2004 16:25 To: CF-Talk Subject: UDF within a Custom Tag I have had a problem a couple times when I've tried to put a UDF within a custom tag. CF insists that the function has been declared more than once. I figured this was because of the sort of doubling effect the start/end execution modes have, but the problem persists even when I have cfif thistag.executionmode is endcfexit method=exittag/cfif at the top of the custom tag. I think that when I've encountered this, I've had to remove the UDF, request-scope it, and put it in the general UDF library, even though it really is just a private method of the custom tag. Solutions? Thanks, Jamie _ _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
RE: UDF within a Custom Tag
I believe this is a known bug - stumbled across it myself a while back. Since then I have resorted to declaring udfs outside a tag Kola -Original Message- From: Jamie Jackson [mailto:[EMAIL PROTECTED] Sent: 21 July 2004 17:17 To: CF-Talk Subject: Re: UDF within a Custom Tag On Wed, 21 Jul 2004 12:11:13 -0400, in cf-talk you wrote: On Wed, 21 Jul 2004 10:45:21 -0500, Raymond Camden [EMAIL PROTECTED] wrote: Are you still running 6.0? I believe they fixed this in 6.1. Nope, running 6.1. Any ideas with that in mind? Might I be doing something wrong? Whoops, I forgot for a moment which environment this app's in. Our CFMX boxes are all 6.1, but this old site happens to be on _CF5_, not MX at all. Thanks, Jamie _ [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 12:00:48 -0400, in cf-talk you wrote: I'd set a request-scoped variable just before or after my function declaration (ie request.functionnameIsDeclared or something else you'll never use anywhere else) and check for its existence. --Ben That's a great idea, and one I hadn't thought of; however, it doesn't seem to work: The following gives the same error I've had all along: cfif NOT isDefined(request.doTocOptionIsDeclared) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } request.doTocOptionIsDeclared = true; /cfscript /cfif The error associated with the above is: Routines cannot be declared more than once. The routine doTocOption has been declared twice in different templates. Furthermore, within cfscript blocks, function declarations seem to be disallowed within conditionals, so the following also doesn't work: cfscript if (NOT isDefined(request.doTocOptionIsDeclared)) { function doTocOption(myQuery, contextFilePrefix) { ... } request.doTocOptionIsDeclared = true; } /cfscript The above yields: Just in time compilation error Invalid parser construct found on line 220 at position 3. ColdFusion was looking at the following text: function Invalid _expression_ format. The usual cause is an error in the _expression_ structure. Lame :( Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 17:36:07 +0100, in cf-talk you wrote: I believe this is a known bug - stumbled across it myself a while back. Since then I have resorted to declaring udfs outside a tag Kola Darn, should have been easy to have private methods in Custom Tags. Oh well, thanks for the sanity check. Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
What about using isCustomFunction() or isFunction from http://cflib.org/udf.cfm?ID=286 Qasim - Original Message - From: Jamie Jackson [EMAIL PROTECTED] Date: Wed, 21 Jul 2004 11:51:39 -0400 Subject: Re: UDF within a Custom Tag To: CF-Talk [EMAIL PROTECTED] On Wed, 21 Jul 2004 16:38:03 +0100, in cf-talk you wrote: You are getting this error as by default Custom Tags are called twice internally AFAIK.. So are UDFs not allowed within Custom Tags? I also tried wrapping the function declaration in a testing conditional: cfif not isdefined(doOption) cfscript function doOption() { ... } /cfscript /cfif But CF complains that doOption is a complex variable, and it can't test for its definition. Is there a way to do an existence test on UDFs, or is there a cleaner way to do UDFs in Custom Tags? Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 13:29:40 -0400, in cf-talk you wrote: What about using isCustomFunction() or isFunction from http://cflib.org/udf.cfm?ID=286 Qasim I just tried your suggestion, and it behaved the same as if I didn't have the conditional in there at all: cfif NOT isFunction(doTocOptionIsDeclared) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif The error associated with the above is: Routines cannot be declared more than once. The routine doTocOption has been declared twice in different templates. Thanks for the reply, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
Shouldn't you be doing this? cfif NOT isFunction(doTocOption) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif or cfif NOT isCustomFunction(doTocOption) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif Qasim - Original Message - From: Jamie Jackson [EMAIL PROTECTED] Date: Wed, 21 Jul 2004 14:12:24 -0400 Subject: Re: UDF within a Custom Tag To: CF-Talk [EMAIL PROTECTED] On Wed, 21 Jul 2004 13:29:40 -0400, in cf-talk you wrote: What about using isCustomFunction() or isFunction from http://cflib.org/udf.cfm?ID=286 Qasim I just tried your suggestion, and it behaved the same as if I didn't have the conditional in there at all: cfif NOT isFunction(doTocOptionIsDeclared) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif The error associated with the above is: Routines cannot be declared more than once. The routine doTocOption has been declared twice in different templates. Thanks for the reply, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
You can also just do isdefined('doTocOption') to see if the function has been created. Brook At 12:39 PM 7/21/2004, you wrote: Shouldn't you be doing this? cfif NOT isFunction(doTocOption) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif or cfif NOT isCustomFunction(doTocOption) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif Qasim - Original Message - From: Jamie Jackson [EMAIL PROTECTED] Date: Wed, 21 Jul 2004 14:12:24 -0400 Subject: Re: UDF within a Custom Tag To: CF-Talk [EMAIL PROTECTED] On Wed, 21 Jul 2004 13:29:40 -0400, in cf-talk you wrote: What about using isCustomFunction() or isFunction from http://cflib.org/udf.cfm?ID=286 Qasim I just tried your suggestion, and it behaved the same as if I didn't have the conditional in there at all: cfif NOT isFunction(doTocOptionIsDeclared) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif The error associated with the above is: Routines cannot be declared more than once. The routine doTocOption has been declared twice in different templates. Thanks for the reply, Jamie -- [http://www.houseoffusion.com/lists.cfm/link=t:4Todays Threads] [http://www.houseoffusion.com/lists.cfm/link=i:4:171584This Message] [http://www.houseoffusion.com/lists.cfm/link=s:4Subscription] [http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=905.825.4Fast Unsubscribe] [http://www.houseoffusion.com/signin/User Settings] [https://www.paypal.com/cgi-bin/webscr?amount=item_name=House+of+Fusionbusiness=donations%40houseoffusion.comundefined_quantity=cmd=_xclickDonations and Support] -- http://www.houseoffusion.com/banners/view.cfm?bannerid=37 [] [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
I just tried your suggestion, and it behaved the same as if I didn't I encountered the same problem once and no suggestion was able to get around the problem. It looks like the function is compiled twice, no matter any CFIF you may put aroud it, even CFIF thisTag.execution mode, nothing. -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
You can also just do isdefined('doTocOption') to see if the function has been created. No matter what you test in the CFIF, even CFIF false, the function will be compiled, once on start, and once on end. IMO It is definitely a bug. -- ___ REUSE CODE! Use custom tags; See http://www.contentbox.com/claude/customtags/tagstore.cfm (Please send any spam to this address: [EMAIL PROTECTED]) Thanks. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 15:39:05 -0400, in cf-talk you wrote: Shouldn't you be doing this? cfif NOT isFunction(doTocOption) cfscript function doTocOption(myQuery, contextFilePrefix) { ... } /cfscript /cfif Yes, sorry, just a typo in the post, but not in my experiment. [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 12:43:39 -0700, in cf-talk you wrote: You can also just do isdefined('doTocOption') to see if the function has been created. Normally, maybe; however, not within the context of a Custom Tag (it just doesn't work). :-/ Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 15:53:27 -0400, in cf-talk you wrote: I just tried your suggestion, and it behaved the same as if I didn't I encountered the same problem once and no suggestion was able to get around the problem. It looks like the function is compiled twice, no matter any CFIF you may put aroud it, even CFIF thisTag.execution mode, nothing. Yup, that's what I'm seeing. Thanks for confirming the behavior, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
Jamie - If you are on CF5 you only have 2 choices really... Use the request scope. You would define the UDF in the request BEFORE you call the custom tag. Ie, Application.cfm may cfinclude a file of UDFs where each UDF is copied to the request scope. You would call the UDF in the CT by using request.foo() In the custom tag, use cfinclude to include the file only in executionMode = start. Both of those will work. On Wed, 21 Jul 2004 16:02:03 -0400, Jamie Jackson [EMAIL PROTECTED] wrote: On Wed, 21 Jul 2004 15:53:27 -0400, in cf-talk you wrote: I just tried your suggestion, and it behaved the same as if I didn't I encountered the same problem once and no suggestion was able to get around the problem. It looks like the function is compiled twice, no matter any CFIF you may put aroud it, even CFIF thisTag.execution mode, nothing. Yup, that's what I'm seeing. Thanks for confirming the behavior, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
On Wed, 21 Jul 2004 15:39:19 -0500, in cf-talk you wrote: Jamie - If you are on CF5 you only have 2 choices really... Use the request scope. You would define the UDF in the request BEFORE you call the custom tag. Ie, Application.cfm may cfinclude a file of UDFs where each UDF is copied to the request scope. You would call the UDF in the CT by using request.foo() In the custom tag, use cfinclude to include the file only in executionMode = start. Hi Ray, I am already using the request scope, I just wanted to know what/if I was doing wrong when trying the UDF declaration within the CT. Since what I was doing is *theoretically* right, I'm satisfied to consider this a bug, and will continue to use the request scope workaround. Thanks for validating the request scope workaround and offering the second (cfinclude) workaround. So, umm, case closed or something. ;-) Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]
Re: UDF within a Custom Tag
It is definitely a bug. It was fixed in either 6.0 or 6.1. And thank goodness it was. :) -Ray On Wed, 21 Jul 2004 17:23:32 -0400, Jamie Jackson [EMAIL PROTECTED] wrote: On Wed, 21 Jul 2004 15:39:19 -0500, in cf-talk you wrote: Jamie - If you are on CF5 you only have 2 choices really... Use the request scope. You would define the UDF in the request BEFORE you call the custom tag. Ie, Application.cfm may cfinclude a file of UDFs where each UDF is copied to the request scope. You would call the UDF in the CT by using request.foo() In the custom tag, use cfinclude to include the file only in executionMode = start. Hi Ray, I am already using the request scope, I just wanted to know what/if I was doing wrong when trying the UDF declaration within the CT. Since what I was doing is *theoretically* right, I'm satisfied to consider this a bug, and will continue to use the request scope workaround. Thanks for validating the request scope workaround and offering the second (cfinclude) workaround. So, umm, case closed or something. ;-) Thanks, Jamie [Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]