|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
UDF in Component?
I'm having trouble. I have a component with a method (addEmail). InBurns, John D 05/07/04 08:21 A You can place a UDF in the component, but it will be treated like a method.Raymond Camden 05/07/04 09:23 A I would guess you would need to take the code from the UDF and make it a method of the Component. Should be fairly straight forward, but I've never tried it.Ian Skinner 05/07/04 09:34 A My code looks like this (simplified version):Burns, John D 05/07/04 09:47 A Oh - no - that's wrong. :) You can't define a UDF in a UDF, or method in aRaymond Camden 05/07/04 09:52 A Ray,Burns, John D 05/07/04 10:34 A You can, however, <cfinclude> the "isEmail" udf within the component methodPaul Kenney 05/07/04 05:31 P Can I strongly recommend against that? Using CFINCLUDE inside a CFC methodBarney Boisvert 05/07/04 05:40 P Oh yeah, I glanced at that thread quickly but didn't really read it... IPaul Kenney 05/07/04 05:50 P I'm having trouble. I have a component with a method (addEmail). In that method, I receive an email address, check to make sure it's not already in the database and then add it. I also want to add functionality for checking to make sure it's a valid email address. I'm using the UDF IsEmail on CFLib.org in some other places so I decided to drop it into that method as well. When I do, I get an error saying: Unable to complete CFML to Java translation. Error information unsupported statement: class coldfusion.compiler.ASTfunctionDefinition Am I not allowed to use UDFs in components? Or am I doing something else wrong? Let me know if you have insight. Thanks. John Burns You can place a UDF in the component, but it will be treated like a method. Tell me - how are you calling the function? I would guess you would need to take the code from the UDF and make it a method of the Component. Should be fairly straight forward, but I've never tried it. My code looks like this (simplified version): <cfcomponent> <cffunction name="addEmail" access="remote" returntype="string"> <cfargument name="emailAddress" required="yes" type="string" default=""> <cfscript> function IsEmail(str) { //supports new top level tlds if (REFindNoCase("^['_a-z0-9-]+(\.['_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+) \.(([a-]{2,3})|(aero|coop|info|museum|name))$",str)) return TRUE; else return FALSE; } </cfscript> <cfif IsEmail(arguments.emailAddress)> <cftry> <cfquery...> </cfquery> <cfcatch></cfcatch> </cftry> </cfif> <cfreturn returnVar> </cffunction> </cfcomponent> Is that incorrect? Let me know. John Burns You can place a UDF in the component, but it will be treated like a method. Tell me - how are you calling the function? Oh - no - that's wrong. :) You can't define a UDF in a UDF, or method in a method, or etc. Simply move the <cfscript> block outside the cffunction declaration. Ray, Thanks for the info. That fixed it. :-) John Oh - no - that's wrong. :) You can't define a UDF in a UDF, or method in a method, or etc. Simply move the <cfscript> block outside the cffunction declaration. You can, however, <cfinclude> the "isEmail" udf within the component method and it is only visible within that method. Paul Kenney paul@pjk.us 916-212-4359 ----- Excess quoted text cut - see Original Post for more ----- Can I strongly recommend against that? Using CFINCLUDE inside a CFC method copies all local variables from that method to the VARIABLES scope (the instanace scope) of the CFC, thoroughly thrashing any encapsulation you had. Cheers, barneyb ----- Excess quoted text cut - see Original Post for more ----- Oh yeah, I glanced at that thread quickly but didn't really read it... I guess I'll do that now. Nevermind my recommendation. Just do what they said ;) Thanks. Paul Kenney paul@pjk.us 916-212-4359 ----- Excess quoted text cut - see Original Post for more -----
|
February 09, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||