views:

471

answers:

3

What is the difference between cfproperty tag defined variable and the variables scope variable in ColdFusion?

I have Java language experience, can you compare the ColdFusion cfproperty variable, variables scope variable to the Java instance variable and class variable?

greate thanks!

+9  A: 

CFPROPERTY is only useful for providing metadata for a component. The only time I ever use them is when creating a component for a Web Service, when they're required.

Here's a TechNote which discusses CFPROPERTY a bit further: http://kb2.adobe.com/cps/191/tn_19169.html

The variables scope is "protected" and only available within the component. The "this" scope variables are public properties. And, of course, any variable declared with the "var" keyword is private to that method.

Here's some more on component scopes: http://www.hemtalreja.com/?p=94

Al Everett
In cf9, cfproperty got a lot of attention and now actually does set up the variables for a component. If you also add in the accessors directive you get default getters and setters as well.
anopres
+5  A: 

Note: cfproperty tag does NOT defined variables.

However, it is helpful when you use CFC Explorer (browse to the CFC directly), so that you can see the properties of the CFC object.

FYI... cfproperty will be much more useful in CF9. See: ORM - Rethinking ColdFusion Database Integration

Henry
You can also use the property metadata with CF8's onMissingMethod to define what properties can be set on a bean.
Nathan Strutz
A: 

cfproperty is useful when using custom objects in remote methods. For example, suppose I had the following component:

<cfcomponent displayname="User">
    <cfset variables.firstName = "first" />
</cfcomponent>

Which I wanted to use as a return to a remote method being consumed via SOAP. I would need to <cfproperty> tags for each variable I wanted to encapsulate in the returned object, in order for that object to be included in the WSDL document as a complex type. Therefore, the component from above would have to be:

<cfcomponent displayname="User">
    <cfproperty name="firstName" type="string" />
    <cfset variables.firstName = "first" />
</cfcomponent>
Ryan McIlmoyl