Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gwt 通过分派发送java.lang.Class的最佳方式?_Gwt_Gwt Platform_Java.lang.class - Fatal编程技术网

Gwt 通过分派发送java.lang.Class的最佳方式?

Gwt 通过分派发送java.lang.Class的最佳方式?,gwt,gwt-platform,java.lang.class,Gwt,Gwt Platform,Java.lang.class,设置如下:我正在使用GWT2.4和GWT平台0.7。我有一系列的类,它们在int->String这个时刻包含键值对。它们只是不同的类,因为它们通过JPA保存到数据库中的不同表中 现在我想要一个!方法从服务器获取此数据 我首先尝试使用ArrayList,HashMap>向服务器发送我想要获取的类。但GWT不允许序列化类。通过这种方式,我可以获得所有数据库条目,并将它们与正确的关联类一起显示,这非常重要 现在,我正在寻找另一种方法来让它工作,而不必编写大量的代码 第一个新想法是有一个HashMap

设置如下:我正在使用GWT2.4和GWT平台0.7。我有一系列的类,它们在int->String这个时刻包含键值对。它们只是不同的类,因为它们通过JPA保存到数据库中的不同表中

现在我想要一个!方法从服务器获取此数据

我首先尝试使用ArrayList,HashMap>向服务器发送我想要获取的类。但GWT不允许序列化类。通过这种方式,我可以获得所有数据库条目,并将它们与正确的关联类一起显示,这非常重要

现在,我正在寻找另一种方法来让它工作,而不必编写大量的代码

第一个新想法是有一个HashMap 我就是这么做的

public Enum ClassType {
  A, B, C
}

public class AType {
  HashMap<Integer, String> myHashMap;
  ClassType getClassType() {
      return ClassType.A;
  }
}

public interface TransferableHashMap extends IsSerializable {
   ClassType getClassType();
}

public interface transferService extends RemoteService {
    HashSet<TransferableHashMap> getMaps(HashSet<ClassType> request);
}


//somewhere on the client
final Set<AType> as = new Set<AType>();
final Set<BType> bs = new Set<BType>();
final Set<CType> cs = new Set<CType>();

Set<ClassType> request = new HashSet<ClassType>();
request.add(ClassType.A);
request.add(ClassType.B);
request.add(ClassType.C);

transferService.getMaps(request, 
  new AsyncCallback<HashSet<TransferableHashMap>>(){

  @Override
  public void onSuccess(HashSet<TransferableHashMap>> result) {
      for (TransferableHashMap entry : result) {
        if(entry instanceof Atype) as.add((AType)entry);
        else if(entry instanceof Btype) bs.add((BType)entry);
        else if(entry instanceof Ctype) cs.add((CType)entry);
        else throw new SerializationException();
        }
    }
  });