如何在ext gwt中实现ModelData接口?

发布于 2024-10-09 04:15:23 字数 1650 浏览 3 评论 0原文

我正在尝试在我正在进行的项目中使用 EditorGrid。我正在使用 EditorGrid grid = new EditorGrid (...)

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

但是,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;
}

我不知道如何处理 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 类型。我做错了什么以及如何让它工作?

I am trying to use an EditorGrid in a project that I am working on. I am using
EditorGrid grid = new EditorGrid (...)

ClassGrade is an object that contains the name, grade (as a Grade object), and credit hours for a class.

However, ClassGrade must implement ModelData. When I tried to implement the interface, there are a few methods that I am not sure how to correctly implement.

@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;
}

I dont know what to do for the get, remove, and set methods, because I do not know what the X means. I tried using

   @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;
}

but that didn't work because the return was not of type X. What am I doing wrong and how do I get this to work?

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

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

发布评论

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

评论(1

倾城月光淡如水﹏ 2024-10-16 04:15:23

我还使用网格等,并使用 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);
}

我希望它对你有用。

I also use grids etc. and use BeanModel class for stores which wants modelData. I implement as below.

public class dto implements IsSerializable, BeanModelTag  {

....//attributes and setter getters.

}

and

convert this object to model as below;

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

I hope it is useful for you.

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