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

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

difference between cfproperty and variables defined with This scope

  << 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:
fun and learning
02/02/2010 01:48 PM

Hi All, Can anyone please tell me the difference between cfproperty tag and variables defined using this scope. Both are used to define CFC properties?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
DURETTE, STEVEN J (ATTASIAIT)
02/02/2010 01:53 PM

According to the docs, cfproperty only sets Metadata.  I just did this recently and even though I could set the initial values I had trouble changing them and using them just inside the cfc. I resorted to <cfset variables.name = "" />  Notice that there is no var in there.  If the variables are outside of a function, you cannot use var. Steve scope Hi All, Can anyone please tell me the difference between cfproperty tag and variables defined using this scope. Both are used to define CFC properties?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
DURETTE, STEVEN J (ATTASIAIT)
02/02/2010 01:55 PM

Opps. I used <cfset name = "" />  didn't put variables in this instance.  I wanted them to only be part of the cfc. Steve This scope According to the docs, cfproperty only sets Metadata.  I just did this recently and even though I could set the initial values I had trouble changing them and using them just inside the cfc. I resorted to <cfset variables.name = "" />  Notice that there is no var in there.  If the variables are outside of a function, you cannot use var. Steve scope Hi All, Can anyone please tell me the difference between cfproperty tag and variables defined using this scope. Both are used to define CFC properties?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Dave Watts
02/02/2010 02:24 PM

> Can anyone please tell me the difference between cfproperty tag and variables defined using this scope. Both are used to define > CFC properties? The answer to this is a bit complicated, and version-dependent. If you're using CF 8 or earlier, the CFPROPERTY tag does nothing but define metadata, as Steven mentioned. This is not especially useful except in a couple of narrow cases. Using CFPROPERTY will show the variable in your automatically-generated documentation (human-readable and WSDL), but it doesn't actually create the variable - you have to do that separately. If you only create the variable and don't use CFPROPERTY, you don't see it in the documentation even though it's actually there. CF 9 changed this significantly. With CF 9, using CFPROPERTY actually creates a public variable in addition to creating documentation. In addition to that, it also "creates" accessors and mutators (setters and getters). It doesn't actually generate visible code in your CFC, but those methods will be available for you to call without you actually writing them. Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ http://training.figleaf.com/ Fig Leaf Software is a Veteran-Owned Small Business (VOSB) on GSA Schedule, and provides the highest caliber vendor-authorized instruction at our training centers, online, or onsite.

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Judah McAuley
02/02/2010 02:56 PM

> CF 9 changed this significantly. With CF 9, using CFPROPERTY actually > creates a public variable in addition to creating documentation. In > addition to that, it also "creates" accessors and mutators (setters > and getters). It doesn't actually generate visible code in your CFC, > but those methods will be available for you to call without you > actually writing them. To clarify a bit further, CF9 added an accesssors="(yes|no)" attribute to the creation of a CFC. If your CFC is defined as Persistent (using the new ORM functionality) this defaults to Yes and those setFoo and getFoo functions will be created implicitly. If you do not set the persistent flag, the value of accessors defaults to No. Then on individual cfproperty tags you can also specify whether to create an accessor and/or mutator for that particular property. I'm not sure what would happen if you set accessors="no" on your cfc and then declared the cfproperty tags with implicit accessor/mutator turned on. I'm guessing that it would ignore the attributes in the cfproperty tags and the variables/functions would not be created. Cheers, Judah

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Aaron Neff
02/04/2010 12:21 AM

Hi fun and learning, In short, variables created via the cfproperty|property-generated setters (in CF9) are private-to-the-CFC. I recommend reading these docs: cfproperty|property: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7e0b.html Implicit Get and Set Functions: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0999c-7ff5.html#WS1E722CDD-3AA0-4e17-86DB-EF6D12FC6750 Also, please note: - "Component properties you assign with the set method are in the Variables scope that is private to the CFC. You can get or reset the properties only by calling get or set methods." - "The default attribute has no effect on the property and does not set an initial property value" - "A direct assignment statement, such as myCFC.MyProp=27 creates a standard This scope variable in the CFC, even if you specify the property in a cfproperty tag. The This scope variable is independent of the properties that you access using the set and get methods. In fact, you can have a This scope variable with the same name as a property that you access using the set and get methods." I wanted to mention those notes, just to clarify that (even in CF9) using cfproperty|property alone does not create an initial variable. In CF9, a private (variables-scope), not public (this-scope), variable can be created using the auto-generated setter (created by cfproperty|property, if accessors="true" on the component). Thanks!, -Aaron Neff =========== > Hi All, > > Can anyone please tell me the difference between cfproperty tag and > variables defined using this scope. Both are used to define CFC > properties?

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Aaron Neff
02/04/2010 12:24 AM

Sry, that should've read: "In short, variables created via the cfproperty|property-generated setters (in CF9) are private-to-the-CFC. And variables in the this scope are public-to-the-CFC." > In short, variables created via the cfproperty|property-generated > setters (in CF9) are private-to-the-CFC.


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

Search cf-talk

May 24, 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 30 31     

Designer, Developer and mobile workflow conference