House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  ColdFusion Talk (CF-Talk)

UDF in Component?

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Burns, John D
05/07/2004 08:21 AM

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

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
05/07/2004 09:23 AM

You can place a UDF in the component, but it will be treated like a method. Tell me - how are you calling the function?

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Ian Skinner
05/07/2004 09:34 AM

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.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Burns, John D
05/07/2004 09:47 AM

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?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Raymond Camden
05/07/2004 09:52 AM

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.

Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Burns, John D
05/07/2004 10:34 AM

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.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Paul Kenney
05/07/2004 05:31 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Barney Boisvert
05/07/2004 05:40 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Paul Kenney
05/07/2004 05:50 PM

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 -----


<< Previous Thread Today's Threads Next Thread >>

Search cf-talk

February 09, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
       1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29