Dec 17 2006
Part 2 – Flex Cairngorm/WebORB Issue Tracker Tutorial – Getting Typed Objects from Rails using [RemoteClass]
This is the second post in a series that covers certain features of Issue Tracker sample app that I added to the Flex RoR SDK.
The first post explained how to set up the application.
This post covers how you can get WebORB for Rails to return typed objects to Flex using the [RemoteClass] metadata tag.
One of the many design patterns that comprises the Cairngorm microarchitecture is the Value Object pattern. Value Objects are used to represent the ‘things’ that you are working with in your application. For example, in the Issue Tracker sample app (view, source) there are currently Value Objects for Users, Projects, and Issues. The class definitions for all of these objects can be found in com.rxr.issuetracker.vo package.
Value Objects on the client generally map to server-side objects. In the Issue Tracker sample app all of the Value Objects listed above map to ActiveRecord classes in Rails, which in turn wrap tables in the database. For instance, the IssueVO class in Flex maps to the Issue class in Rails (see C:\rails\rails_issue_tracker2\app\models\issue.rb) which wraps the issues table in the database.
This is the IssueVO class in Flex:
package com.rxr.issuetracker.vo
{
import com.adobe.cairngorm.vo.IValueObject;
[Bindable]
[RemoteClass(alias="com.rxr.issuetracker.vo.Issue")]
public class IssueVO implements IValueObject
{
public var id : int;
public var project_id : String;
public var reportedby : String;
public var assignedto : String;
public var description : String;
public var status : String;
public var priority : String;
}
}
Which maps to:
class Issue < ActiveRecord::Base
end
Which wraps the issues table:

Prior to WebORB 1.0.9 this mapping was only conceptual, in that Rails would only return untyped objects or ObjectProxys that would have to be 'manually' converted to Value Objects on the client side. Since WebORB 1.0.9 it is now possible to directly map ActiveRecord classes to classes on the Flex side using the [RemoteClass] metadata tag in Flex.
Making this happen is pretty straight-forward:
First, you need to add a [RemoteClass(alias="")] metadata tag just above the class definition of the ActionScript class that you want mapped to an ActiveRecord class.
[Bindable]
[RemoteClass(alias="com.rxr.issuetracker.vo.Issue")]
public class IssueVO implements IValueObject
{
Next, go to C:\rails\rails_issue_tracker2\config and open weborb-config.xml. In this file you need to specify the mapping between your client-side class and your server-side class. For example, the following xml maps the IssueVO class on the client to the Issue class on the server. Note that you use the string specified in the alias of the [RemoteClass] metadata tag as the value of the clientClass in the class mapping.
<classMapping>
<clientClass>com.rxr.issuetracker.vo.Issue</clientClass>
<serverClass>Issue</serverClass>
<source>Issue</source>
</classMapping>
That's it. Now when you make a service call to a method that returns Issue objects in Rails, those objects are automatically returned as IssueVOs to Flex.





 
 
 
