Reputation: 1509
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!
Upvotes: 5
Views: 3456
Reputation: 221
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>
Upvotes: 0
Reputation: 32905
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
Upvotes: 6
Reputation: 6430
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
Upvotes: 12