Dec 17

Part 2 – Flex Cairngorm/WebORB Issue Tracker Tutorial – Getting Typed Objects from Rails using [RemoteClass]

Tag: Flex and Rails, tutorialDerek Wischusen @ 1:41 am

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:

issue_table2

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.

vo_debugger

14 Responses to “Part 2 – Flex Cairngorm/WebORB Issue Tracker Tutorial – Getting Typed Objects from Rails using [RemoteClass]”

  1. Niels says:

    Great tutorial, but what are the advantages of VO’s and mapping them with RoR?

  2. Wilkes Joiner says:

    It looks like a lot of this code could be generated in similar manner to rails scaffolding, even a lot of the state machine for Cairngorm. Any plans for this?

  3. Derek Wischusen says:

    Wilkes,

    I agree. I think that nearly all of the code in this sample app could be generated.

    I know that Alex MacCaw was working on a Rails Cairngorm generator, but I am not sure where he is at with this project. You can read his post about it here: http://www.eribium.org/?p=34

    WebORB for .NET includes generators for Cairngorm (http://blog.themidnightcoders.com/2006/11/weborb-for-net-30rc1-is-released.html), and I believe that the Midnight Coders are planning to migrate all of the functionality in the .NET version to the Rails version.

  4. Derek Wischusen says:

    Niels,

    Advantages of VOs:

    If used typed VOs then you have control over the definition of the objects that you are working with. You can control what interfaces they implement, which properties are [Bindable], what methods they have, etc.

    Using the VO design pattern as a convention will make it easier for others to understand your code.

    Steven Webster (Cairngorm\’s author) describes some other benefits in his ariticles about Cairngorm. Go to: http://www.adobe.com/devnet/flex/articles/cairngorm_pt2_03.html and scroll down to \’Introducing the Value Object / Data Transfer Object Pattern\’

    Advantage of mapping with WebORB:

    If you decide that you want to use VOs, then the advantage to using mapping with WebORB is that you do not have to manually convert the untyped objects that your service calls would normally return to your typed VOs.

    Disadvantage:

    The disadvantage to this approach is that it ties you to a back-end that implements mapping with the [RemoteClass] metadata tag. So if you want to switch back-ends you will either have to choose another that implements this functionality, or you will have to write code to manually do the conversion.

    Derek

  5. Getting Typed Objects from Rails, Part 2 in tutorials from Flexonrails.net at Web 2.0 Log says:

    [...] The second tutorial about the Issue Tracker Flex Application is online. This one is about Getting Typed Objects from Rails using [RemoteClass]. I asked him in de in the comments what the advantages are of VO’s and mapping them with Ruby: [...]

  6. Alastair says:

    Hi Derek,

    Thanks for this it’s a great tutorial, and not just because it’s the only one of its kind ;)

    I’m confused by the user login, there appears to be no service for it, is it built-in to WebORB?

    Also I saw that WebORB now has setCredentials implemented could this example be tweaked to use it?

    thanks!
    Alastair

  7. Vixiom Axioms » Flex loop over form values (mx:Form, mx:FormItems) says:

    [...] I’ve been messing around with the FlexOnRails Cairngorm/WebORB app and wanted to add some more fields to the flex form for projects (I’m building a construction project tracker so I need to add the project’s address). However as I’m a lazy programmer I quickly got tired of typing all the values to be passed in the event dispatcher. Here’s the original code: [...]

  8. Derek Wischusen says:

    Hi Alastair,

    The userService is a bit confusing at first. If I weren’t such a lazy SOB I would have commented the code to make it easier to understand.

    If you crack open /config/WEB-INF/flex/remoting-config.xml you will see that the userServiceImpl is mapped directly to the User Active Record instance :

    <destination id=”userServiceImpl”>
    <properties>
    <source>User</source>
    </properties>
    </destination>

    So when you call a method on userServiceImpl it is as though you are calling it directly on the User class in Rails.

    Please note that I am not advocating this practice, I just threw this in there to show that it is possible.

    I plan to cover this feature in a future tutorial.

    I do plan to add setCredentials to this app, but it is my understanding that current implementation in WebORB for Rails is only an iterim solution that will soon be replaced by a more robust solution. So once the update comes out I will add it to the sample app.

    Best,

    Derek

  9. Alastair says:

    cool thanks, that clears things up for me.

  10. flexonrails.net » Blog Archive » Part 3 - Flex Cairngorm/WebORB Issue Tracker Tutorial - Using ActiveRecord Associations with WebORB says:

    [...] The second post covered how you can get WebORB for Rails to return typed objects to Flex using the [RemoteClass] metadata tag. [...]

  11. flexonrails.net » Blog Archive » Part 4 - Flex Cairngorm/WebORB Issue Tracker Tutorial - Invoking ActiveRecord Methods Directly From Flex says:

    [...] The second post covered how you can get WebORB for Rails to return typed objects to Flex using the [RemoteClass] metadata tag. [...]

  12. flexonrails.net » Blog Archive » Sending Typed Value Objects from Flex to Rails using WebORB and the [RemoteClass] metadata tag says:

    [...] that I have been writing about the Issue Tracker sample app (view, source) I discussed how you can Get Typed Objects from Rails using [RemoteClass]. Now, with the latest version of WebORB, it is also possible send typed objects from Flex to [...]

  13. Flash The Ripper says:

    BTW, Ruby on Rails Cairngorm Generator is released by Ilya Devers and it includes generator for WebOrb Service class.

    Also it does:
    * Take your application name and create typical Cairngorm structure, including modelLocator, frontController, services.mxml and application itself. You can also set the package structure.
    * Create (server) delegates.
    * Generate Cairngorm Commands, Events and comments.
    * Create standalone events and value objects (though author acknowledges that it could make more sense to create VOs based on model classes).

    You can donwload it from Google Code: Ruby on Rails Cairngorm Generators set.

    Also, Michael Klishin has posted a great article named “Ruby / DSL Saves Your Soul and Makes You a Happy Flex developer” (Google translation from Russian).

  14. Ian says:

    Hi Derek,

    Nice tutorial – I wonder if you ran into any problems with nested classes? I have a service that happily returns a ProfilVO, a LoginVO and even a ProfileVO.LoginVO (loginVO member of profileVO). But when I return a ProfilVO containing a LoginVO, the LoginVO’s members are all ‘null’. Did you run into this at all?

    Thanks,

    Ian

Leave a Reply

Cheap xanax bars
Cheap cialis soft tabs
Blood pressure and prednisone
Generic xanax xr
Viagra express delivery
Pharmacy tramadol
No prescription valium
Xanax overnight cod
Valium no rx
Buy brand name viagra
Cheap tramadol cod
Buy xanax online without prescription
Viagra fast delivery
Viagra prescription cost
Canada viagra
Cialis cialis
Prescription free viagra
Buying viagra in new zealand
10mg valium effects
Viagra canada mastercard
Valium without prescription
Cheapest levitra
Propecia online uk
Phentermine online uk
Purchase phentermine online
Buy viagra australia
Side effects of viagra
Buy viagra 100mg
Viagra no prescription online
Buy viagra uk online
Cialis 20mg side effects
Viagra for sale online
Best price on phentermine
Phentermine cheap online
Mail order phentermine
Free cialis online
Low cost levitra
Viagra discount coupons
Canada pharmacy valium
Viagra canada online
Viagra price canada
Valium online fast delivery
Where to buy levitra online
Cheap valium online
Prescription valium
Tramadol cod delivery
Valium online overnight
Buy valium cheap online
Cialis over the counter
Cialis soft tabs online
Cheap 100mg viagra
Viagra pills for sale
Cheap cialis viagra
Xanax no prescription required
Buying cialis
Viagra cheap no prescription
Cialis discount price
Tramadol no prescription required
Tramadol without prescription
Cheap levitra uk
Cialis online canadian pharmacy
Xanax 1mg side effects
Buy viagra online cheap
Buy cialis online from canada
Online prescription tramadol
Pfizer viagra price
Generic viagra super active
Ordering cialis online
Order tramadol online cod
Phentermine 37.5 wholesale
Viagra without prescription uk
Generic cialis overnight
Fedex tramadol
Xanax bars dosage
Viagra india price
Generic cialis uk
Low cost cialis
Buying cialis online without a prescription
Cheap xanax for sale
Valium cheapest
Where to buy viagra online
Genuine viagra online
Viagra canadian online pharmacy
Phentermine without a prescription
Buy phentermine online without prescription
Buy valium no rx
100mg tramadol effects
Xanax generic dosage
Overnight tramadol no prescription
Cheap cialis india
Tramadol india
Order tramadol cod
Buy generic propecia uk
Where to buy cialis without prescription
Low price viagra
Purchase phentermine
Phentermine 37.5 buy online
Buy viagra online in australia
Where to buy propecia in canada
Buying tramadol in uk
Buy phentermine online no prescription
Cialis prices uk
Brand viagra cheap
Get tramadol prescription
Valium pill 10mg
Levitra samples
Buy xanax overnight
Levitra online cheap
Viagra dosage information
2mg xanax no prescription
Viagra shop online
Overnight xanax delivery
Online prescriptions xanax
Purchase cialis without a prescription
Best price tramadol
Buy generic valium
Buy levitra
Buy tramadol overnight
Buy phentermine hcl 37.5 no prescription
Where to buy phentermine cheap
Discount viagra usa
Overnight delivery viagra
How to buy phentermine online
Generic viagra 100mg
Buy cheap viagra online uk
Tramadol cheapest
Xanax no rx
Buy generic phentermine online
Tramadol pharmacy
Cialis purchase online
Buying valium in spain
Viagra pharmacy uk
Dose of xanax
Buy xanax 2mg no prescription
Viagra generic
Xanax bars side effects
Cheap phentermine without prescription
Viagra online cheap
Purchase xanax
Viagra indian pharmacy
Buy valium without prescription uk
Buy cialis brand
Phentermine 37.5mg side effects
Prednisone tablets 10 mg
Cheap viagra online without prescription
Viagra in the uk
Cost of viagra 50mg
Generic viagra online without prescription
Buy viagra in canada online
Buy propecia
Buying xanax online without prescription
Xanax 1 mg dose
Tramadol without prescription overnight delivery
Viagra 50mg side effects
Cheapest place to buy viagra online
Buy phentermine no script
Cialis 20mg
Cialis canada no prescription
Phentermine purchase online
Viagra tablets for sale
Buy cialis viagra
Buy female viagra without prescription
Best price cialis
Propecia uk prices
Tramadol online overnight
Propecia price
Propecia generic canada
Buy phentermine no rx
Xanax with no prescription
Cialis ordering
Cheap generic viagra
Xanax for sale without prescription
Xanax bars effects
Viagra lowest prices
Propecia cheap
Levitra us
Viagra pharmacy prices
Prescription propecia
Generic cialis tadalafil
Buy viagra online in ireland
Drug phentermine
Buy propecia cheap
Prednisone online
Viagra sale uk
Viagra canada prices
Prescription phentermine online
Ordering propecia from canada
Cialis for sale
Cialis medication
Phentermine buy uk
Tramadol no prescription overnight delivery
Tramadol prescription online
Real phentermine without prescription
Valium 10 mg
Cheap cialis pills
Buying levitra without prescription
Phentermine 37.5 mg
Cialis price
Viagra in france
Prescription viagra canada
Cheapest online cialis

Viagra to buy
Buy generic valium online
Generic tramadol
Viagra purchase uk
Levitra purchase
Get viagra
Prednisone 20mg side effects
Best levitra prices
40 mg prednisone side effects
Cialis order online
Generic xanax no prescription
Cheap cialis
Discount viagra pills
Tramadol free shipping
Levitra price
Order prednisone no prescription
Valium generic
Free samples of cialis
Tramadol for sale
Cialis uk sales
Buy xanax canada
Buy tramadol cod
Where can i buy viagra in the uk
Order cheap phentermine
Where to buy cialis online
Cialis order canada
Cheap propecia without prescription
Where can i buy cialis without a prescription
Where can i buy viagra without a prescription
Best way to take tramadol
Cheap levitra no prescription
Phentermine online free shipping
Best prices for cialis
Phentermine hcl no prescription
Canada viagra no prescription
Free cialis samples
Buy levitra online canada
Buy generic cialis
Authentic phentermine 37.5
Australia viagra online
Xanax online cheap
Cialis samples canada
Viagra prescription
Where to buy cialis safely
Valium online uk
Buy pfizer viagra without prescription
Brand name cialis
Buying viagra in london