RemoteObjectAMFO update to latest Cairngorm

Posted on July 26, 2006 | 38 comments

[lang_en]
The RemoteObjectAMF0 class and sample code have been updated to reflect the latest Cairngorm package. You can find Cairngorm for Flex2 on the labs.adobe.com site. I will not be packaging Cairngorm with my RemoteObjectAMF0 samples any more.

There are now 2 examples in the RemoteObjectAMF0 package. The first is the updated Cairngorm login example (see in action / source).

The new example I created is a non-Cairngorm AMFPHP example (see in action / source ).
[/lang_en]
[lang_zh]
为了表现最新的Cairngorm包那些RemoteObjectAMF0的类别和标本代码已经更新了。在labs.adobe.com的网站你可以找到Flex2的Cairngorm。从现在开始我RemoteObjectAMF0的类别不会包括Cairngorm。

现在的RemoteObjectAMF0包,包括两个例子。第一就是更新的Cairngorm注册例子 (例子/代码程序)。

我所创造的新例子是一个non-Cairngorm AMFPHP的例子。(例子/代码程序)。
[/lang_zh]

  • Matt Brailsford

    Hi,

    I’d just like to say that your work is fantastic.

    I do have one question, if i use it as documented, it does work great, but i am trying to get it to work using Darron Schall’s method which can be found here:

    http://www.darronschall.com/weblog/archives/000234.cfm

    I think the problem lies within the RemoteObjectAMF0 class in the setQueryResult and Faul methods, the dispatched event is not being picked up.

    Would you know of any way to get this to work?

    ps, in the setProperty method, i think you have mis spelled “destination” and in the setQueryFault method i didn’t know if you wanted to use the FaultEvent.FAULT constant, rather than the sting “fault”

  • http://www.websector.de/ sectore

    Hi Renaun,

    thanks for sharing your code.

    At the example above I had a problem to execute the LoginCommand. It took me some minutes to realize that the CairngormEventDispatcher had not been initialized before. The function named “loginUser” at Login.mxml dispatched the LoginEvent without an instance of the CairngormEventDispatcher. When I changed the code to
    CairngormEventDispatcher.getInstance().dispatchEvent( event ); it has worked well.

    Anyway, great work Renaun!

    Best
    sectore

    http://www.websector.de/

  • http://www.renaun.com Renaun Erickson

    matt,
    I made the string changes you recommended. As far as the Fault event not being called I would have to see your code, it works here. I updated the Example and source with the small changes and a Fault example.

    You can send me some example code if you want me to look at it further.

    sectore,

    I am not sure why you had to do this as the code works straight from the source for me. Did you modified the source any? what version are you using of Cairngorm? are you using the Cairngorm source or SWC?

    Renaun

  • http://www.mikebritton.com Mike Britton

    Thanks for putting this together.

    I typically establish my AMFPHP gateway as ‘http://www.someurl.com/flashservices’.

    From the AMFPHP gateway, is ‘amfphp1_2/services/com/multispan/samples/CairngormAMFPHPLoginExample/Login.php’ the same as ‘http://www.someurl.com/flashservices/services/com/multispan/samples/CairngormAMFPHPLoginExample/Login.php’?

    That is, should I place the package in my AMFPHP /services directory?

  • http://www.renaun.com Renaun Erickson

    The amfphp1_2 is where the gateway.php is and the services folder is the default location for AMFPHP for the AMFPHP service classes.

    Place the PHP files starting from com/renaun/etc… (get the newer code) in your services folder under the AMFPHP installation root.

  • Matt Brailsford

    Hi,

    I’ve uploaded my code so far, which is basically just the login sample, so you should be pretty familiar with it.

    I am using fluorine, which does support AMF3 but has to be used the same way as Remoting at the mo, so i have commented out the AMF0 encoding bit, which as i mentioned before works fine the way you documented it, but if i switch it round to Darron Schall’s method, i never get a measage from the methods mentioned before.

    Anyway, you can access my code from here:

    http://www.gradiation.co.uk/FlexDemo.zip

    Your help is greatly apprechiated.

  • http://www.mikebritton.com Mike Britton

    Thanks sectore for finding that problem w/ CainrgormEventDispatcher — that fixed my problem and I now have a semi-working version of this.

    Matt, as soon as I take a nap and have a beer I’m going to take a look at your code. It would be nice to have AMF3 working since (I think) that means we could use the standard RemoteObject component.

  • http://www.renaun.com Renaun Erickson

    I have not come across the CairngormEventDispatcher issue, what versions of Cairngorm are you using? Are you using the latest from labs.adobe.com? is it source or SWC?

    Matt, I am going to look at your code here soon.

    I did start looking into AMF3 which would make the RemoteObjectAMF0 less important unless you did not want to upgrade your old AMF classes. Flourine or SabreAMF say they support AMF3 but that leaves all the channel and destination implementation glue left to figure out that Flex now uses in the “services-config.xml” config file. I haven’t had time to check it out in depth.

    Renaun

  • Matt Brailsford

    I know zoli is trying to get something working by the end of the summer for Fluorine, so i was just trying to get something working in the mean time.

    If you are trying to figure out the AMF3 glue bits, it might be worth a look at WebORB as it sounds like they are doing something interesting utilizing some of the FDS classes or something, without actually using FDS.

  • http://www.renaun.com Renaun Erickson

    Well the CairngormEventDispatcher issue was valid, I guess I have to many versions and in the switch over to using the SWC it appeared. It is fixed now in the sample code thanks sectore.

    Matt, Mike,
    I also updated the ResponderAMF0.as class to handle IResponder tied to the AsyncToken. This fixes the classes to work as the normal Responder should, and how Darron Schall explains it.

    You’ll find the updated source in the same place.

    Renaun

    PS: I want to go back and clean up the code and document it better once I get a change.

  • http://www.mikebritton.com Mike Britton

    I know this is trivial, but BookVO doesn’t run in PHP 4.4.2. I var’ed the properties and it worked:

    class BookVO {
    var $_explicitType = “BookVO”;
    var $name;
    var $bookid;
    var $publishdate;

    function BookVO() {}

    }

  • http://www.renaun.com Renaun Erickson

    Yeah, the zipped source version is for PHP 5 and to get it to work in PHP 4 you need to change the public to var in the BookVO.php.

  • http://www.mikebritton.com Mike Britton

    Once the DataGrid is populated, I see its change event hits viewDetails() to fetch the value from the BookVO. It was blowing up for me, so I switched the function from

    lblBook.text = BookVO( dgBooks.selectedItem ).name;

    to

    var myCollection:ArrayCollection = new ArrayCollection();
    myCollection = model.books;
    var myCursor:IViewCursor = myCollection.createCursor();
    var myValue:String = myCollection.getItemAt(dgBooks.selectedIndex).name;
    lblBook.text = myValue;

    Is this the “right” way to do it?

  • http://www.mikebritton.com Mike Britton

    Sorry – change that to:

    var myCollection:ArrayCollection = new ArrayCollection();
    myCollection = model.books;
    var myValue:String = myCollection.getItemAt(dgBooks.selectedIndex).name;
    lblBook.text = myValue;

    The cursor was unnecessary.

  • http://www.renaun.com Renaun Erickson

    Mike,

    I am interested to know why it was blowing up. They change you did works fine as its just accessing the Collection directly instead of through the Datagrid.

  • http://www.mikebritton.com Mike Britton

    TypeError: Error #1034: Type Coercion failed: cannot convert Object@d8fb0e1 to com.renaun.samples.login.vo.BookVO.

  • http://www.renaun.com Renaun Erickson

    Its probably because you did not specify the type of objects in the ArrayCollection. In your ModelLocator do you have something like this:

    [ArrayElementType("com.renaun.samples.vo.BookVO")]
    public var books:ArrayCollection;

  • http://www.mikebritton.com Mike Britton

    Yep, it still threw that error. Which brings me to ask: is it bad form to access the model directly from a view like I did? It feels bad.

  • http://www.websector.de/ sectore

    Mike,

    cast the resultEvent at the resultHandler (LoginCommand) with a helper method as following:

    // change in the method "onResult"
    ModelLocator.getInstance().books = initBookVOs(event.result);
    // and add a helper method
    private function initBookVOs (resultArray: Array): ArrayCollection
    {
    [ArrayElementType("com.renaun.samples.vo.BookVO")]
    var tempArray: ArrayCollection = new ArrayCollection();

    for (var book: String in resultArray)
    {
    tempArray.addItem(new BookVO(resultArray[book]));
    }
    return tempArray;
    }

    In the same way you have to change the BookVO:

    package com.renaun.samples.login.vo
    {

    import com.adobe.cairngorm.vo.ValueObject;
    import flash.net.registerClassAlias;

    [RemoteClass(alias="com.renaun.samples.login.vo.BookVO")]

    [Bindable]
    public class BookVO implements ValueObject
    {
    public var name : String;
    public var bookid : String;
    public var publishdate : String;

    public function BookVO(source:Object=null)
    {
    if (source != null)
    {
    for (var element:String in source)
    {
    try
    {
    this[element] = source[element];
    }
    catch (error:Error)
    {
    // throw new Error ("BookVO" + error);
    }
    }
    }
    }
    }
    }

    P.S. Renaum, I’m using the latest Cairngorm Framework from labs.adobe.com.

    Best
    sectore
    –
    http://www.websector.de/

  • http://www.renaun.com Renaun Erickson

    I forgot to mention that Mike’s issue with the BookVO coercion error was a incorrect linve of code in BookVO.php.

    Needed line:
    var $_explicitType = “com.renaun.samples.login.vo.BookVO”;

  • http://www.mikebritton.com Mike Britton

    Thanks sectore! Renaun set me straight as well.

  • http://www.websector.de/ sectore

    Renaun,

    if I use your code with the Cairngorm Framework (*.as classes, not the *.swc) and run the “CairngormAMFPHPExample2.mxml”, the Flash Player throws at executing the viewDetails() method the following error message:


    TypeError: Error #1034:
    Type Coercion failed:
    cannot convert Object@79ab641 to com.renaun.samples.login.vo.BookVO.

    at CairngormAMFPHPExample2/::viewDetails()
    at CairngormAMFPHPExample2/__dgBooks_change()
    at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.controls.listClasses::ListBase/mx.controls.listClasses:ListBase::mouseUpHandler()
    at mx.controls::DataGrid/mx.controls:DataGrid::mouseUpHandler()

    Casting the bookVO in the method named onResult (LoginCommand.as) as described above solves this problem.

    I think the array of the result has got elements typed as “simple” Object (not BookVOs). But I’m not sure because haven’t got the Flex Debugger on my Powerbook…

    P.S. I’m using Flex SDK, FP 9.0.16.0, AMFPHP 1.2, PHP5.

    Best
    sectore

    http://www.websector.de/

  • Mike B

    Nothe the Cairngorm and Remote object examples are not showing the date in the published date column of the grid.

    I get the following trace warnings in the FB debugger.

    TypeError: Error #1034: Type Coercion failed: cannot convert “August 31, 2006, 12:00 am” to Date.
    TypeError: Error #1034: Type Coercion failed: cannot convert “September 1, 2006, 12:00 am” to Date.
    TypeError: Error #1034: Type Coercion failed: cannot convert “November 1, 2006, 12:00 am” to Date.

    any ideas?

    thanks for your effort!

  • http://www.renaun.com Renaun Erickson

    showBusyCursor has been implemented and is in the the source now.

  • http://www.rooftopsolutions.nl/ Evert Pot

    Hi Renaun,

    Thanks for the heads up, SabreAMF now does support the Flex messaging system glue..

    Evert

  • Stefan Schmalhaus

    Is there any solution to the date mapping problem between Flex and PHP? (Comment #23)

  • http://www.renaun.com Renaun Erickson

    AMFPHP as of yet only lets you define a “Date” type for returned values of a remote method. There is no distinct way to know a field in PHP is a date, so you will have to explicit do the conversion manually.

    This is more of a short coming of PHP then AMF.

  • Pingback: Sam Shrefler » Flex + Cairngorm + WebOrb 2.0 Standard (Free) + .NET Sample Application / Tutorial

  • http://blog.shrefler.net Sam Shrefler

    Renaun:

    Thank you so much for the excellent tag. I’ve been able to use it with WebOrb.NET as well with great results. I was looking to attempt to extend the tag so that it would include a timeout. Reason being, i’d like to throw up a modal window when a request is sent to the server, but if for some reason a response isn’t returned, the user would be locked out. It seems to make most sense to me to incorporate right into the Service call, a timeout that if it occured, it would return a fault event? What are your thoughts on this?

    Thanks

    Sam

  • http://www.renaun.com Renaun Erickson

    You could extend the class to provide this functionality.

    If you are using Cairngorm you could also do the same thing with a base Command object.

    I believe this is something specific to your needs (maybe others too), but to keep the class close to the generic RemoteObject I would consider this feature an add-on. If you need any help let me know it should be fairly easy.

  • http://blog.shrefler.net Sam Shrefler

    Renaun:

    Could you elaborate on where to do this using a base Command object in Cairngorm. I agree that this would be an add-on in order to keep it similar to RemoteObject..but it seems like this would be something that many people would be looking to have. I’m wondering if it is implemented somewhere else and I’m missing it….

  • Matt Brailsford

    Hi Renaun,

    I’ve been happily using your RemoteObject with Fluorine and Flex 2 for a few weeks now, however i have come up with a problem.

    Collections of objects that are returned from fluorine are converted into basic Arrays instead of ArrayCollections (which are needed for binding)

    I’m not sure if this is a Fluorine thing, or RemoteObject thing, but whilst looking into it i found that all RPC Services in flex have a makeObjectsBindable property which forces Arrays to ArrayCollections.

    I was just wondering, with your knowlege of the internals of RemoteObject, do you know how this is implemented? is it the RemoteObject that forces them? or doe it tell the service to do it? and how could it be implemented into your RemoteObject?

    Any help, as always, is greatly apprechiated.

    Many thanks

    Matt

  • http://www.renaun.com Renaun Erickson
  • Pingback: Sam Shrefler » Flex + Cairngorm + Fluorine + .NET Sample Application / Tutorial

  • Pingback: Sam Shrefler » Adobe Flex 2.0 + Cairngorm + Fluorine + ASP.NET Sample Application / Tutorial

  • Matt Brailsford

    Hi Renaun

    I’m trying to use RemoteObjectAMF0 in a real simple example, that doesn’t use cairngorm. I’m trying to bind a datagrid to the results public property, however it doesn’t seem to bind.

    Don’t suppose you have any ideas why? Or any examples of how best to do it without cairngorm?

    Many thanks

    Matt

  • Ilya

    Hi Renaun,
    I get the following error, then use RemoteObjectAMF0:
    TypeError: Error #1034: Type Coercion failed: cannot convert com.renaun.rpc::RemoteObjectAMF0@4359e61 to mx.rpc.remoting.RemoteObject
    I shall be grateful for any help

  • http://www.renaun.com Renaun Erickson

    It looks like you have some casting wrong somewhere. Is there something in your code where you are doing RemoteObject( roAMF0 )?

    Is RemoteObject class present anywhere in your code?
    What backend are you using RemoteObjectAMF0 with?

  • http://tercume-burosu.org Tercüme bürosu

    Yeah, the zipped source version is for PHP 5 and to get it to work in PHP 4 you need to change the public to var in the BookVO.php…

  • Dan Van Brunt

    Renaun,
    Can you please provide an example of what you mean regarding your response on 2006-08-21 at 7.29 am regarding AMF, PHP and Date conversions?

    I’m currently have this error with Dates as well as passing nested VOs from PHP to Flex using AMFPHP.

    eg. TeamVO has a property “players” that I’m trying to pass as an array of PlayerVOs.

    Is this even possible?

  • Pingback: Renaun Erickson » Getting WebORB for PHP Working

  • http://nateross.wordpress.com Nate Ross

    Here is how you map the Date successful using AMFPHP.

    Send the date over in milliseconds as a Number. Then you can do the following…

    private var _birthdate:Date;
    public function set birthdate(value:*):void {
    if (value is Number || value is String) {
    _birthdate = new Date();
    _birthdate.setTime(value);
    }
    }
    public function get birthdate():Date {
    return _birthdate;
    }

    Voila!