无法运行GWT ServiceAsync

时间:2012-06-19 17:11:59

标签: java gwt rpc gwt-rpc asynccallback

我正在尝试创建一个asyncallback来返回一个列表,其中包含来自app-engine中GAE JDO数据库的所有客户。我已经完成了一个运行良好的登录类,但只返回一个字符串。现在我想获得一个List,但我有来自的错误:

18:05:39.219 [ERROR] [prototipov8]    subtype   
com.google.gwt.resources.client.impl.ExternalTextResourcePrototype.ETRCallback is not default 
instantiable (it must have a zero-argument constructor or no constructors at all) and has no 
custom serializer. (reached via
com.google.gwt.user.client.rpc.AsyncCallback<java.util.List<pt.sites.shared.model.Customer>>)

[ERROR] [prototipov8] - subtype com.google.gwt.user.client.rpc.AsyncCallback<T> 
is not instantiable

完整错误:

17:54:07.268 [ERROR] [prototipov8] Unable to load module entry point class pt.info2000.sites.client.old.Main (see associated exception for details)
 java.lang.RuntimeException: Deferred binding failed for 'pt.info2000.sites.client.old.TableService' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at pt.info2000.sites.client.old.Main.<clinit>(Main.java:30)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:654)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:363)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:595)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at pt.info2000.sites.client.old.Main.<clinit>(Main.java:30)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:654)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:363)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)

电话

        public static final TableServiceAsync table = GWT.create(TableService.class);

TableService

@RemoteServiceRelativePath("getObjects")
 public interface TableService extends RemoteService {

List<Customer> getObjects(AsyncCallback<List<Customer>> callback);

  }

TableServiceAsync

  public interface TableServiceAsync {

    void getObjects(AsyncCallback<List<Customer>> callback, 
             AsyncCallback<List<Customer>> asyncCallback);

  }

Costumer.class一个JDO in gae

 @PersistenceCapable

public class Customer extends User implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

@Persistent
private Date birthDate;

@Persistent
private int nib;

@Persistent
public Set<Key> companies;

@Persistent
public Set<Key> sugestions;

@Persistent
public Set<Key> documents;

/**
 * @param code
 * @param name
 * @param description
 * @param creationDate
 * @param modificationDate
 * @param creator
 * @param lastModifier
 * @param username
 * @param password
 * @param avatar
 * @param activo
 * @param cookie
 * @param loginIP
 * @param roles
 * @param contacts
 */
public Customer(int code, String name, String description,
        Date creationDate, Date modificationDate, Key creator,
        Key lastModifier, String username, String password, Blob avatar,
        boolean activo, String cookie, String loginIP, Set<Key> roles,
        Set<Key> contacts) {
    super(code, name, description, creationDate, modificationDate, creator,
            lastModifier, username, password, avatar, activo, cookie, loginIP,
            roles, contacts);
}

public Customer() {

}

我已经尝试找到解决方案,但我无法使其正常工作,是否有人遇到此错误?任何建议或解决方案?提前感谢您阅读本文所需的时间。任何可以帮助的代码请询问。

Edit1:我有一个没有参数的默认构造函数,类实现了serializable,我可以序列化它。此代码适用于Customer类;

Serializable c = new Customer(); 

Edit2:添加了请求的代码和完整的错误。试图将列表传递给hashset,但错误仍然存​​在。没有找到任何其他解决方案。

2 个答案:

答案 0 :(得分:1)

为了使对象成为Serializable,它需要一个没有参数的默认构造函数。这就是这个错误所说的。如果对象是Serializable,则只能将对象从客户端传递到服务器端(反之亦然)。

答案 1 :(得分:1)

您的界面错误。你应该阅读GWT documentation来进行RPC调用。

您的TableService接口应该如下所示,假设您不需要该方法的任何参数。

@RemoteServiceRelativePath("getObjects")
public interface TableService extends RemoteService {
    List<Customer> getObjects();
}

您的TableServiceAsync将如下所示

public interface TableServiceAsync {
    void getObjects(AsyncCallback <List<Customer>> callback);
}

AsyncCallback不是Serializable,这就是您遇到此错误的原因。如果您需要将参数传递给您的方法,例如一个字符串数组来标识要获取的客户,您的界面将如下所示

@RemoteServiceRelativePath("getObjects")
public interface TableService extends RemoteService {
    List<Customer> getObjects(String[] ids);
}

public interface TableServiceAsync {
    void getObjects(String[] ids, AsyncCallback <List<Customer>> callback);
}