2010-12-22 25 views
0

我想在我正在处理的项目中使用EditorGrid。我正在使用 EditorGrid网格=新的编辑器网格(...)如何在ext gwt中实现ModelData接口?

ClassGrade是一个对象,其中包含名称,成绩(作为成绩对象)和学分的课时。

但是,ClassGrade必须实现ModelData。当我尝试实现接口时,有一些方法我不确定如何正确实现。

@Override 
public <X> X get(String property) { 
    if (property.equals("name")) 
     return this.getClassName(); 
    if (property.equals("hours")) 
     return this.getHours(); 
    if (property.equals("grade")) 
     return this.getGrade(); 
    return null; 
} 

@Override 
public Map<String, Object> getProperties() { 
    Map<String, Object> propMap = new HashMap<String, Object>(); 
    propMap.put("grade", this.getGrade()); 
    propMap.put("hours", this.getHours()); 
    propMap.put("name", this.getClassName()); 
    return propMap; 
} 

@Override 
public Collection<String> getPropertyNames() { 
    ArrayList<String> props = new ArrayList<String>(); 
    props.add("grade"); 
    props.add("hours"); 
    props.add("name"); 
    return props; 
} 

@Override 
public <X> X remove(String property) { 
    // TODO Auto-generated method stub 
    return null; 
} 

@Override 
public <X> X set(String property, X value) { 
    // TODO Auto-generated method stub 
    return null; 
} 

我不知道该如何去做,删除和设置方法,因为我不知道X是什么意思。我试过使用

@Override 
public <X> X get(String property) { 
    if (property.equals("name")) 
     return this.getClassName(); 
    if (property.equals("hours")) 
     return this.getHours(); 
    if (property.equals("grade")) 
     return this.getGrade(); 
    return null; 
} 

但这并没有工作,因为返回不是类型X.我做错了什么,我怎么得到这个工作?

回答

1

我也使用网格等,并使用BeanModel类的商店,它需要modelData。我执行如下。

public class dto implements IsSerializable, BeanModelTag { 

....//attributes and setter getters. 

} 

转换此目的是如下模型;

public static <E> BeanModel toModel(E e) { 
    BeanModelFactory factory = BeanModelLookup.get().getFactory(e.getClass()); 
    return factory.createModel(e); 
} 

我希望它对你有用。

+0

非常感谢。现在我已经用CellTable做了,但是当我有空的时候,我想给EditorGrid另一个去。 – 2010-12-23 07:58:30