Author: TomdeMan
Related Categories:
Transfer, ColdFusion
July 26, 2007
Transfer was built to allow you to extend its capabilities. Using the Decorator Pattern you can overlay/overwrite methods of a TransferObject and add methods of your own. Remember its a Decorator to the Transfer Object(the Bean). So the methods you add should be relative to the Bean. To add DB or other external functions, there are other ways.
Here's how you setup the Decorator.
1. Add the decorator attribute to the object element in your Transfer Config XML file.
<package name="Account">
<object name="Account" table="Account" decorator="model.account.accountDecorator" >
<id name="AccountId" type="UUID" generate="true"/>
<property name="Username" type="string" nullable="false" />
<property name="Password" type="string" nullable="false" />
<property name="FirstName" type="string" nullable="true" />
<property name="LastName" type="string" nullable="true" />
<property name="Email" type="string" nullable="false" />
<property name="UpdatedOn" type="date" nullable="false" />
<property name="CreatedOn" type="date" ignore-update="true" />
</object>
</package>
</objectDefinitions>
2. Create your Decorator CFC and extend the Transfer Decorator Object.
<cffunction name="setPassword" access="public" returntype="void" output="false" hint="Replaces original setPassword to MD5 Hash the Password">
<cfargument name="password" type="string" required="true" />
<cfset getTransferObject().setPassword(hash(password)) />
</cffunction>
</cfcomponent>
You also have access to getTransfer() when you extend the Transfer Decorator Object.
That's it. Re-init Transfer and your Decorator methods will now be available from your Transfer Objects.
To take it a step further, I have created a Base Decorator to share methods accross Decorators. But that's another Blog.





Comments:
(Comment Moderation is enabled. Your comment will not appear until approved.)
[Add Comment]