Ung, Seng schrieb:

Daniel:
Thank you!
Insteresting, I would like to see a completed example for this....
If you have sometime???!! Could you write us an example of how it can be use.
Ung, in my ContentObjects I have a function which 'reads' the properties defined by CFPROPERTY- actually they inherit from an Abstract BaseObject.

<!--- a method for traversing the metaData to get properties up the tree, by default, looks at this ---> <cffunction name="getAllProperties" access="public" output="no" returnType="struct" hint="a method for traversing the metaData to get properties up the tree, by default, looks at this "> <cfargument name="metaDataToCheck" required="false" default="#getMetaData(this)#" type="struct">
   <cfset var ii = 1>
   <cfset var allProperties = structnew()>
   <cfscript>
           //if this component is extended, recurse up the tree
           if(structKeyExists(arguments.metaDataToCheck,"extends")){
allProperties = getAllProperties(arguments.metaDataToCheck.extends);
           }
//append these properties to allProperties; allow overwrite to allow children properties to over-ride parents structAppend(allProperties,getProperties(arguments.metaDataToCheck),true);
       </cfscript>
   <cfreturn allProperties>
 </cffunction>

<!--- get the properties from a specific meta data or component instance (by default, this) ---> <cffunction name="getProperties" access="private" output="no" returnType="struct" hint="get the properties from a specific meta data or component instance (by default, this)"> <cfargument name="metaDataToCheck" required="false" default="#getMetaData(this)#">
   <cfset var ii = 1>
   <cfset var theseProperties = structnew()>
   <cfset var thisProperty = 0>
   <!--- if it's an object, get it's metaData --->
   <cfif isObject(arguments.metaDataToCheck)>
<cfset arguments.metaDataToCheck = getMetaData(arguments.metaDataToCheck)>
   </cfif>
   <cfscript>
//if this metaData has properties, loop through them, populating a struct of properties
           if(structKeyExists(arguments.metaDataToCheck,"properties")){
for(ii = 1; ii LTE arrayLen(arguments.metaDataToCheck.properties); ii = ii + 1){
                   thisProperty = arguments.metaDataToCheck.properties[ii];
                   theseProperties[thisProperty.name] = thisProperty;
               }
           }
       </cfscript>
   <!--- return the struct of properties collected --->
   <cfreturn theseProperties>
 </cffunction>

The two functions return a struct with the properties. These struct with properties data I send to a persister component where I build the sql for CRUD operations according to the properties at runtime.

Finally I have 'hibernate-like' generic persistence functionality like myObject.save(), myObject.update(), and ....

You could do the same thing by defining the object properties in an external XML-file. For me to do it with cfproperty was just simpler and convient enough
for the purpose of the application.

Let me know if this was helpful.

Daniel Schmid


Thanks
Seng Ung

-----Original Message-----
From: Daniel Schmid [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 10, 2005 9:51 AM
To: [email protected]
Subject: Re: [CFCDev] sean: lesson of cfproperty?


2. It adds to the metadata for a CFC
 This can be useful for documentation purposes or tools that depend
on introspection however I don't advise building systems that perform
dynamic introspection (at runtime) since they often don't scale very
well.

maybe I get beaten to death, but I heavily use <cfproperty> for instrospection 
on a CMS system (not Farcry, even if I know it does it as well)

my CFC content objects look like this...

<cfcomponent displayname="ArticleObject" hint="This is the article">
        <cfproperty name="title" type="string" default="New Article"/>
        <cfproperty name="subtitle" type="string" default="" />
        <cfproperty name="teaser" type="longchar" default="" />
        <cfproperty name="publishstart" type="date" default="" />

....

with getMetaData() I get all the properties and build a generic CRUD 
persistance layer around it. works since cf 6.0 like a charm...

the use of cfproperty makes it somehow easy - otherwise I would have to write 
properies down in a xml-file (like hibernate does)

regards
daniel www.danielschmid.name



Sean Corfield schrieb:

On 11/7/05, Ung, Seng <[EMAIL PROTECTED]> wrote:


I am having a very tough time to understand what cfproperty does.
<cfproperty> does two things:

1. It describes public instance data in a CFC that is intended to be
the return type of a web service (or, in some cases, passed into a web
service).
 Since CFML is essentially a typeless language, the <cfproperty> tag
provides information needed by the web service libraries to map
between a CFC and a strongly typed structure. Really this is just a
way to provide structs in CFML that have enough information associated
with them (metadata) to allow interaction with strongly typed web
services.

2. It adds to the metadata for a CFC
 This can be useful for documentation purposes or tools that depend
on introspection however I don't advise building systems that perform
dynamic introspection (at runtime) since they often don't scale very
well.

In other words, most people actually won't need to use <cfproperty>.

If you're calling a web service that returns a strongly typed
structure containing two elements (C++ syntax):

struct Result {
 double amount;
 String currency;
}

The equivalent CFML code would be:

Result.cfc:
<cfcomponent>
 <cfproperty name="amount" type="numeric"/>
 <cfproperty name="currency" type="string"/>
</cfcomponent>

The returned object would be used like this:

<cfset result = ws.callMethod() />
<cfset amount = result.amount />
<cfset currency = result.currency />

(Caveat: all untested code off the top of my head - errors & omissions
excepted :)
--
Sean A Corfield -- http://corfield.org/
Got frameworks?

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]








----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]




----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]






----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at 
www.mail-archive.com/[email protected]


Reply via email to