Transfer ORM and Flex

Recently I’ve been working on a project to deliver something that was more proof of concept which in a business sense building something in a relatively short time frame.

I decided to develop the front end with Flex 3 and the back end with ColdFusion 8 using the flex remoting classes to connect the two together. Having chatted recently to a couple of fellow developers there was a consensus among them that documentation for connecting both ColdFusion and Flex was underdone and that it could possibly be the Achilles heel in using CF as the server side technology.

I myself haven’t found any issues in connecting the two together. Sure there are a couple of files that need to be configured everything hangs together harmoniously. Compared to other technologies like webOrb and amfPHP it’s relatively painless.

Transfer
Due to the nature of the beast I needed something that would look after my CRUD methods on the server side. I didn’t want to have to spend time hand writing this code and having seen a couple of presentations on Transfer it made sense to use this as my ORM. For those of you that don’t know about Transfer it’s an ORM for Coldfusion. It allows you to create your object relational mappings of your database allowing you to perform simple to complex database transactions. More information on Transfer can be found here. I then used Transfer to plug into a lightweight CF framework that I had custom built some time ago that I normally use for Flash and Flex development using the facade pattern to expose the required services.

Other Code Generating Tools
I also use the Illudium PU-36 Code generator developed by Brian Rinaldi to help create the ORM mappings and services and gateways for the required objects. You can download and read more about this code generator here on the RIAforge website.

These two great tools allow me to create the server model fairly quickly allowing to spend more time planning and creating the UI.

Setting up Transfer to work with Flex
You first need to setup your objects on the client and server. If you are using Cairngorm on the client these would be your Value Objects. On the server these would be your Objects that your Transfer objects would be extending.

I’ll be using the blog application that ships with Transfer as the examples. Hopefully I’ll be able to post the running application once I’ve completed it.

In your flex value object.

package com.riality.tblog.vo
{
import com.adobe.cairngorm.vo.IValueObject;

[RemoteClass(alias="tblog.com.PostVO")]

[Bindable]
public class PostVO implements IValueObject
{

public var IDPost:String = "";
public var Title:String = "";
public var Body:String = "";

public function PostVO()
{
}

}
}

The important part here is your RemoteClass metatag. This must correlate to the Value object in your CF framework. This is done by extending your transfer object inside your Transfer.xml to an Object that can bind to your flex value object.

Example inside your Transfer.xml



... etc

Note inside your Transfer Post Object extends your custom defined Post object. This in turn extends the “transfer.com.TransferDecorator” which allows you object to bind to Flex with all the necessary getters and setters for the declared properties.

Example of the custom defined Post Object





If you weren’t using Flex as your view you wouldn’t need to declare your properties here as Transfer creates the required getters and setters. However Flex needs these properties declared to map your bindable Flex class.

Now to connect the two together you just need to setup your facade to allow flex to get to your necessary services.

Example in your facade.cfc






The above gets the instance of you Post service and calls the method getpost which is basically a wrapper for your transfer call.

Example inside your postservice.cfc





Once you’ve set that all up all you need to do now is dispatch your Cairngorm event to allow your delegate to connect to your facade. Which I won’t go into detail inside this post, as it’s the bread and butter in working with Cairngorm.

This is a quick overview of setting up the required infrastructure to get Transfer working with Flex. Hopefully it gives some insight into connecting Flex, Coldfusion and Transfer together.

Downloads

4 thoughts to “Transfer ORM and Flex”

  1. I have yet to use Transfer with Flex, so thanks for posting an example of how to get them working together. I just wanted to point out that in your sample code from Transfer.xml, where you have:

    <object name="Post" table="tbl_Post" extends=’tblog.com.PostVO’>

    I believe it should be:

    <object name="Post" table="tbl_Post" decorator=’tblog.com.PostVO’>

    The attribute is called "decorator", not "extends.

  2. Sounds cool for the push up, but the question is – how are you bringing the data back down?

    I’ve not done much Flex work, so I’m interested to see how people are solving this problem.

  3. Hi Mark,

    For setting data from the Flex UI I use the generated set methods created from the Illudium code generator. As the value object coming back from flex gets passed to this method as an argument collection which in turn uses the TransferObject’s setters to push the passed values into the Transfer Object before calling the save method.

    eg
    <code>
    <cfset var Post = variables.transfer.get("post.Post" ,arguments.id) />

    <cfif len(arguments.id)>
    <cfset Post.setid(arguments.id) />
    </cfif>

    etc..

    <cfset variables.transfer.save(Post) />

    </code>

Leave a Reply

Your email address will not be published. Required fields are marked *