开发者

GWT - Hashmap is null in response?

开发者 https://www.devze.com 2023-04-12 03:58 出处:网络
I have a custom model, which internally uses HashMap<String, Object> to store the data. public class SearchScreenConfigModel extends DefaultDataModel implements Serializable{

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 fro开发者_如何学运维m 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号