我正在尝试在我正在处理的项目中使用 EditorGrid。我在用 EditorGrid grid = new EditorGrid(...)
ClassGrade 是一个对象,其中包含类(class)的名称、成绩(作为 Grade 对象)和学时。
但是,ClassGrade 必须实现 ModelData。当我尝试实现该接口(interface)时,有一些方法我不确定如何正确实现。
@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;
}
我不知道如何处理 get、remove 和 set 方法,因为我不知道 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 类型。我做错了什么以及如何让它工作?
最佳答案
我还使用网格等,并使用 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);
}
希望对您有用。
关于java - 如何在ext gwt中实现ModelData接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4514081/