【问题标题】:Can't find objects in ArrayList passed to server through GWT-RPC在通过 GWT-RPC 传递给服务器的 ArrayList 中找不到对象
【发布时间】:2013-06-12 07:13:41
【问题描述】:

我有一个ArrayListShortcutVirtualSystemEntry,其中:

public class ShortcutVirtualSystemEntry extends VirtualSystemEntry implements IsSerializable {

  public ShortcutVirtualSystemEntry(String id, String label, String image,
      String tooltip, String parent, int x, int y, int tray, Command action) {
    super(id, label, image, tooltip, parent, x, y, tray, action);
  }

public ShortcutVirtualSystemEntry() {

}

}

当我尝试通过RPC 调用将ArrayList 从客户端传递到服务器时,列表中的所有对象都已实例化但没有数据 这里是 RPC:

docService.saveDocument2(shortcuts,
                new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        Window.alert("Faliled");
                        caught.printStackTrace();
                    }

                    @Override
                    public void onSuccess(Void result) {
                        Window.alert("Success");

                    }
                });

服务器端:

@Override
public void saveDocument2(
        List<ShortcutVirtualSystemEntry> shortcuts) {
    for(ShortcutVirtualSystemEntry v: shortcuts)
    {
        System.out.println("Image "+v.getImage());// Prints : Image null...
    }


}

那么为什么我必须丢失我的列表数据?我做错了什么

提前非常感谢:)

【问题讨论】:

  • 在你的代码中 Aysnc 调用返回的对象列表

标签: java google-app-engine gwt collections gwt-rpc


【解决方案1】:

我对 GWT 了解不多。但是 RPC 的共同规则是确保集合中的元素也是可序列化的。因此,如果您要发送可序列化的列表,但列表中的对象不可序列化,那么您将无法通过 RPC 正确获取元素。因此,请确保列表中的对象是可序列化的。

【讨论】:

  • 虽然我知道那个信息,但由于我的愚蠢,我忘记了 Command 这是ShortcutVirtualSystemEntry 可序列化的字段
【解决方案2】:

据我所知,您的代码应该可以工作。可能您的问题出在其他地方,即您忘记在构造函数中设置 Image 或者您只是没有设置 Image。

GWT 的重要之处在于,您通过 RPC 发送的对象是可序列化的,而且通常还有助于为这些对象创建一个空的构造函数。

萨拉乔格

【讨论】:

    猜你喜欢
    • 2010-10-31
    • 2013-01-26
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多