|
Mailing Lists
|
Home /
Groups /
ColdFusion Talk (CF-Talk)
UDF in Component?
Author: Paul Kenney
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162617
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 -----
Author: Barney Boisvert
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162616
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 -----
Author: Paul Kenney
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162615
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 -----
Author: Burns, John D
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162530
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.
Author: Raymond Camden
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162525
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.
Author: Burns, John D
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162523
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?
Author: Ian Skinner
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162519
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.
Author: Raymond Camden
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162517
You can place a UDF in the component, but it will be treated like a method.
Tell me - how are you calling the function?
Author: Burns, John D
Short Link: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:32369#162515
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
|
May 24, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||