6

我已经通过 BlazeDS 向我的 Flex 应用程序公开了一个 Spring bean。在我的 Java 代码中,我返回强类型列表。例如

public List<Folder> getFolders(String path) {
    return dao.getFolders(path);
}

Flex 应用程序将数据作为 AS3 对象实例的 ArrayCollection 接收 - 即不是作为我想要的文件夹的 ArrayCollection。我已将我的 Flex 类注释如下:

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() {}
    }
}

我检查了我的 Java Folder 类上是否有 getter/setter 以匹配我的 Flex Folder 类中的属性。有任何想法吗?

4

4 回答 4

11

经过一番谷歌搜索,我终于解决了这个问题。以下是我发现的 Flex 远程处理规则:

  1. 注释 Flex 值对象以指示与其相关的 Java 类。如果包名称不同,这是必不可少的。– 例如 [Bindable][RemoteClass(alias=”package.JavaClass”)] public class FlexClass {}

  2. The constructors MUST match in Flex and Java value objects. I ended up sticking to public no-args constructors just to keep it simple.

  3. Getters and setters MUST match between Flex and Java value objects.

  4. 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.

于 2009-11-19T16:21:09.137 回答
0

我正在查看我所有的服务器端代码,我不记得这是否必要,但在 Java 端,我将返回值声明为强类型列表:

public List<Folder> getFolders(String path) { 
    return dao.getFolders(path); 
}
于 2009-11-18T18:07:40.993 回答
0

Java 泛型在编译时被剥离。JVM 在运行时不键入集合。无论如何,我没有看到您的调用代码,但它应该将 java 的返回值放入一个声明如下的变量中:

folders:ArrayCollection.<String>
于 2009-11-19T08:12:45.260 回答
0

您提到您的文件夹类很复杂;这是否意味着它包含对其他对象的引用?在这种情况下,您是否不必映射所有其他类(并检查设置器/获取器,尤其是布尔值)?

于 2009-11-19T09:09:12.493 回答