Learning CF9: Implicit Getters and Setters
Posted on October 18, 2009 at 2:50 PM in ColdFusion
One of the (many) really nice features of CF9 is the addition of implicit getters and setters for CFCs. While I love having a concrete API, I am learning to love this idea more and more because of the saved keystrokes.
Housekeeping
Before we go any further, let me go ahead and say it:
Yes, I know that in the purest form, what CF9 calls "implicit getters and setters" is not actually accurate. However, for the sake of simplicity and continuity with the CF9 documentation, I am going to use the term "implicit". If you don't like it, get over it.
What Implicit Getter/Setter Does
According to the CF9 docs...
"By default, properties that you specify by using the <cfproperty> tag have implicit setPropertyName and getPropertyName methods that access the PropertyName property in the CFC variables scope."
Translation: If you have the following...
- <cfproperty name="Foo" />
... CF9 will automatically generate the following two methods for you:
- <cffunction name="getFoo">
- <cfreturn variables.foo />
- </cffunction>
- <cffunction name="setFoo">
- <cfargument name="foo" />
- <cfset variables.foo = arguments.foo />
- </cffunction>
However, the documentation is wrong. Perhaps "wrong" is too strong a word, but the docs are certainly inaccurate and incomplete. In order to actually get CF9 to behave in this manner, you must also add the 'accessors' attribute to your <cfcomponent> tag.
- <cfcomponent accessors="true">
With this in place, CF9 will now generate the get/set{Property} methods for you on properties that you have defined with <cfproperty>.
Latest Articles
- cfUniForm: "Rate Me"
- cfUniForm Quick Tip: Struct or String
- cfUniForm v.4.0 - Leaner, Meaner, More Features - Just ...
Categories
- ColdBox (21) [RSS]
- ColdFusion (78) [RSS]
- Fusebox (3) [RSS]
- General (14) [RSS]
- jQuery (10) [RSS]
- Kalendar (1) [RSS]
- Rants (4) [RSS]
- Transfer (8) [RSS]
- Uni-Form Tag Library (30) [RSS]
Quick Links
Blogs I Read
Calendar
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| « Feb | ||||||
| 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 | |||
Subscribe
Enter a valid email address.


There are no comments for this entry.
[Add Comment]