GWT - 哈希映射响应为空?
我有一个自定义模型,它在内部使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用
对象
: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.