GWT SimpleBeanEditorDriver - 生成编辑器类

发布于 2024-12-27 09:58:51 字数 296 浏览 1 评论 0原文

我在 stackoverflow 中看到了很多与我的问题类似的问题,但还没有看到与我的问题描述相同的问题。所以,问题是:

我正在使用 GXT 构建相当大的 Web 应用程序。我需要制作数百个带有可编辑字段的窗口。我想要的是制作一个生成器,在运行时根据 DataModel 生成编辑器 UI。但我不明白如何做到这一点,因为编辑器字段名称必须与 DataModel 字段名称匹配(也可以使用 @Path 注释)。无论哪种方式知道这一点,都不可能在运行时基于 DataModel 字段列表生成字段。 Editor 类必须在编译时构建。有没有办法在运行时生成编辑器字段?

I've seen many questions in stackoverflow that are similar to mine, but haven't seen problem described as mine. So, here is the question:

I am building quite huge web application using GXT. I need to make couple of hundreds windows with editable fields. What I want is to make generator that would generate Editor UI according to DataModel in runtime. But I can't see how this can be done as Editor field names has to match DataModel field names (@Path annotation can be used as well). Either way knowing this it is not possible to generate fields based on DataModel field list in runtime. The Editor class has to be built at compile time. Is there a way I could generate editor fields in runtime?

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

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

发布评论

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

评论(1

旧人九事 2025-01-03 09:58:51

这至少需要识别模型,但类似的事情将为您的模型构建一个基本的 UI。

 public void BuildUI(TargetFieldMapping model) {
      //Generate a factory for this model to cover to BeanModel
      BeanModelFactory curFactory = BeanModelLookup.get().getFactory(model.getClass());

      //Create a bean from this model
      BeanModel bean = curFactory.createModel(model);

      //Loop through the properties
      for(String s : bean.getPropertyNames()) {
          //Get value
          Object obj = bean.get(s);

          //for each data type generate a different field type
          if(obj instanceof Integer) {
              NumberField field = new NumberField();
              field.setName(s);
              field.setFieldLabel(s);
              add(field);
          }
          //Etc etc...
      }
}

希望这能让您走上正轨

This would require at least the model to be identified but something like this would build you a basic UI for your model.

 public void BuildUI(TargetFieldMapping model) {
      //Generate a factory for this model to cover to BeanModel
      BeanModelFactory curFactory = BeanModelLookup.get().getFactory(model.getClass());

      //Create a bean from this model
      BeanModel bean = curFactory.createModel(model);

      //Loop through the properties
      for(String s : bean.getPropertyNames()) {
          //Get value
          Object obj = bean.get(s);

          //for each data type generate a different field type
          if(obj instanceof Integer) {
              NumberField field = new NumberField();
              field.setName(s);
              field.setFieldLabel(s);
              add(field);
          }
          //Etc etc...
      }
}

Hope this gets you on the right track

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