GWT - 哈希映射响应为空?

发布于 2024-12-09 04:40:50 字数 2660 浏览 0 评论 0原文

我有一个自定义模型,它在内部使用 HashMap 来存储数据。

public class SearchScreenConfigModel extends DefaultDataModel implements Serializable{

private static final long serialVersionUID = 1L;

private ArrayList<DefaultGridColumnModel> defaultGridColumnModels;
private EntityTblModel entityTblModel;
private DefaultGridColumnModel defaultGridColumnModel;

public List<DefaultGridColumnModel> getDefaultGridColumnModels() {
    return get("defaultGridColumnModels");
}

public void setDefaultGridColumnModels(List<DefaultGridColumnModel> defaultGridColumnModels) {
    set("defaultGridColumnModels", defaultGridColumnModels);
}

public String getScreenName() {
    return get("screenName");
}

public void setScreenName(String value) {
    set("screenName", value);
}

public String getIcon() {
    return get("icon");
}

public void setIcon(String icon) {
    set("icon", icon);
}

public void setEntityTbl(EntityTblModel entityTbl) {
    set("entityTbl", entityTbl);
}

public EntityTblModel getEntityTbl() {
    return get("entityTbl");
}

我正在从服务器端设置数据

public class DefaultDataModel implements DataModel, Serializable {

private static final long serialVersionUID = 1L;

private HashMap<String, Object> map;
protected boolean allowNetstedValues;

public DefaultDataModel(){

}

public DefaultDataModel(Map<String, Object> properties){
    super();
    setProperties(properties);
}


@SuppressWarnings("unchecked")
@Override
public <X> X get(String property) {
    if(map == null)
        return null;
    return (X)map.get(property);
}

@Override
public Map<String, Object> getProperties() {
    if(map != null)
        return map;
    return new HashMap<String, Object>();
}

@Override
public Collection<String> getPropertyNames() {
    Set<String> set = new HashSet<String>();
    if( map != null)
        set.addAll(map.keySet());
    return set;
}

@SuppressWarnings("unchecked")
@Override
public <X> X remove(String property) {
    if(map == null)
        return null;
    return (X) map.remove(property);
}

@SuppressWarnings("unchecked")
@Override
public <X> X set(String property, X value) {
    if(map == null)
        map = new HashMap<String, Object>();
    return (X)map.put(property, value);
}

public void setProperties(Map<String, Object> properties){
    for(String property : properties.keySet())
        set(property, properties.get(property));
}

(包括原始对象和用户定义的对象 - 可序列化)并发送回客户端

在从服务器返回之前,地图具有数据。

一旦模型在客户端接收到,哈希图就为空。

任何人请帮助我。

I have a custom model, which internally uses HashMap<String, Object> to store the data.

public class SearchScreenConfigModel extends DefaultDataModel implements Serializable{

private static final long serialVersionUID = 1L;

private ArrayList<DefaultGridColumnModel> defaultGridColumnModels;
private EntityTblModel entityTblModel;
private DefaultGridColumnModel defaultGridColumnModel;

public List<DefaultGridColumnModel> getDefaultGridColumnModels() {
    return get("defaultGridColumnModels");
}

public void setDefaultGridColumnModels(List<DefaultGridColumnModel> defaultGridColumnModels) {
    set("defaultGridColumnModels", defaultGridColumnModels);
}

public String getScreenName() {
    return get("screenName");
}

public void setScreenName(String value) {
    set("screenName", value);
}

public String getIcon() {
    return get("icon");
}

public void setIcon(String icon) {
    set("icon", icon);
}

public void setEntityTbl(EntityTblModel entityTbl) {
    set("entityTbl", entityTbl);
}

public EntityTblModel getEntityTbl() {
    return get("entityTbl");
}

}

public class DefaultDataModel implements DataModel, Serializable {

private static final long serialVersionUID = 1L;

private HashMap<String, Object> map;
protected boolean allowNetstedValues;

public DefaultDataModel(){

}

public DefaultDataModel(Map<String, Object> properties){
    super();
    setProperties(properties);
}


@SuppressWarnings("unchecked")
@Override
public <X> X get(String property) {
    if(map == null)
        return null;
    return (X)map.get(property);
}

@Override
public Map<String, Object> getProperties() {
    if(map != null)
        return map;
    return new HashMap<String, Object>();
}

@Override
public Collection<String> getPropertyNames() {
    Set<String> set = new HashSet<String>();
    if( map != null)
        set.addAll(map.keySet());
    return set;
}

@SuppressWarnings("unchecked")
@Override
public <X> X remove(String property) {
    if(map == null)
        return null;
    return (X) map.remove(property);
}

@SuppressWarnings("unchecked")
@Override
public <X> X set(String property, X value) {
    if(map == null)
        map = new HashMap<String, Object>();
    return (X)map.put(property, value);
}

public void setProperties(Map<String, Object> properties){
    for(String property : properties.keySet())
        set(property, properties.get(property));
}

}

I am setting the data from the server side (both primitive as well as user defined objects - serializable) and sending back to client.

Before returning from server the map has the data.

Once the model received in the client side, the hashmap is null.

Anyone please help me out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国际总奸 2024-12-16 04:40:50

您不能使用对象http:// /code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideSerializedTypes。这可能可以解释为什么您无法在客户端中获取数据。您需要将其重写为所有子类型都可以序列化的类型。这也是Object的问题。 GWT 为可序列化对象的所有子类型生成代码,因为在编译时它不知道运行时使用哪个子类型。对于对象来说,这基本上意味着所有类,这意味着生成的代码会产生巨大的开销,而这些代码可能永远不会被使用。

You can't use Object: http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes. This would probably explain why you won't get data in the client. You need to rewrite it to a type of which all subtypes can be serialized. This is also the problem with Object. GWT generates code for all subtypes for serializable objects, because at compile time it doesn't know which subtype is used at runtime. For Object that would mean basically all classes, which would mean a huge overhead of generated code that will probably never be used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文