Author: TomdeMan
Related Categories:
Transfer, ColdFusion
July 26, 2007
So you have a few methods you want to include in every Transfer Object, and you don't want mess with mix-ins, and copy/paste isn't an option. You want to extend it but its already extending the transfer.com.TransferDecorator. So what can you do?
1. Create your Base Decorator CFC, and extend the transfer.com.TransferDecorator.
<cffunction name="listProperties" access="public" returntype="string" output="false" hint="Returns a List of the Properties">
<cfset var lReturn = '' />
<cfset var oIterator = getTransfer().getTransferMetaData(this.getClassName()).getPropertyIterator() />
<cfloop condition="#oIterator.hasNext()#">
<cfset lReturn = listAppend(lReturn,oIterator.next().getName()) />
</cfloop>
<cfreturn lReturn />
</cffunction>
<cffunction name="listColumns" access="public" returntype="string" output="false" hint="Returns a List of the Properties">
<cfset var lReturn = '' />
<cfset var oIterator = getTransfer().getTransferMetaData(this.getClassName()).getPropertyIterator() />
<cfloop condition="#oIterator.hasNext()#">
<cfset lReturn = listAppend(lReturn,oIterator.next().getColumn()) />
</cfloop>
<cfreturn lReturn />
</cffunction>
</cfcomponent>
2. Now change the 'extends' in the object decorator to extend the Base Decorator CFC
<cffunction name="setPassword" access="public" returntype="void" output="false" hint="Replaces default setPassword method to MD5 Hash the Password">
<cfargument name="password" type="string" required="true" />
<cfset getTransferObject().setPassword(hash(password)) />
</cffunction>
</cfcomponent>
Now you'll have the baseDecorator and the accountDecorator methods available to you from your TransferObject.
Wait...What if you only need to extend the baseDecorator to your TransferObject and don't forsee a need for an accountDecorator? Dont create an empty accountDecorator just to extend the baseDecorator.
Change the value of the decorator attriute in the Transfer Config XML to the path of your baseDecorator.



Comments:
[Add Comment]