I've exposed a Spring bean to my Flex app via BlazeDS. In my Java code I return strongly typed lists. e.g.
public List<Folder> getFolders(String path) {
return dao.getFolders(path);
}
The Flex app receives the data as an ArrayCollection of AS3 Object instances - i.e. not as a ArrayCollection of Folders which is what I want. I've annotated my Flex class as follows:
package myproject.vo {
import com.adobe.cairngorm.vo.IValueObject;
import mx.collections.ArrayCollection;
[Bindable]
[RemoteClass(alias="myproject.vo.Folder")]
public class Folder extends PersistentObject implements IValueObject {
public function Folder() {}
}
}
I checked that I had getters/setters on my Java Folder class to match the properties in my Flex Folder class. Any ideas?
I finally resolved this issue following a bit of Googling. Here are the rules of Flex remoting that I found:
Annotate the Flex value object to indicate the Java class that it relates to. This is essential if the package name differs. – e.g. [Bindable][RemoteClass(alias=”package.JavaClass”)] public class FlexClass {}
The constructors MUST match in Flex and Java value objects. I ended up sticking to public no-args constructors just to keep it simple.
Getters and setters MUST match between Flex and Java value objects.
The last rule is a cracker – You MUST instantiate any classes that you need to deserialize to. On the face of it this shouldn’t be a problem however I spent days trying to deserialize the results of a remote getObjectsAtPath() call - a list of PersistentObjects which contained instances of Folder and Document (both are subclasses of PersistentObject). If you don’t explicitly instantiate the class (in my case the Folder class) it does NOT get included in the SWF file (unlike Java)! I eventually create a dummy variable of type Folder to get around this.
Thanks to everyone for your suggestions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With