【问题标题】:GWT: use the same UI template for multiple pages?GWT:对多个页面使用相同的 UI 模板?
【发布时间】:2010-04-13 19:11:06
【问题描述】:

如何将同一个 UI 模板(*.ui.xml 文件)与从 Composite 扩展的多个 Java 对象一起使用?

我需要构建几个页面,这些页面应该以相同的布局显示基本相同的信息,但是在一个页面上某些字段是可编辑的,而在不同的页面上其他字段是可编辑的。我想在 ui.xml 中只指定一次布局,并在不同的 *.java 类中创建不同的行为。

Eclipse 在

上给我一个语法错误“FirstAppUI.ui.xml is missing”
@UiTemplate("Template.ui.xml")
public class FirstAppUI extends Composite {
  interface FirstAppUIUiBinder extends
          UiBinder<Widget, FirstAppUI> {
  }
}

谢谢! 简·普鲁萨科娃

【问题讨论】:

    标签: eclipse gwt uibinder


    【解决方案1】:

    我认为您需要将 @UiTemplate 注释放在 Binder 上,而不是 Composite 类上

    此代码适用于我:

    public class TestUiBinder extends Composite {
    
      @UiTemplate("SomeTemplate.ui.xml")
      interface TestUiBinderUiBinder extends UiBinder<Widget, TestUiBinder> {}
      private static TestUiBinderUiBinder uiBinder = GWT.create(TestUiBinderUiBinder.class);
    
      public TestUiBinder() {
        initWidget(uiBinder.createAndBindUi(this));
      }
    }
    
    public class AnotherTestUiBinder extends Composite {
    
      @UiTemplate("SomeTemplate.ui.xml")
      interface TestUiBinderUiBinder extends UiBinder<Widget, AnotherTestUiBinder> {}
      private static TestUiBinderUiBinder uiBinder = GWT.create(TestUiBinderUiBinder.class);
    
      public AnotherTestUiBinder() {
        initWidget(uiBinder.createAndBindUi(this));
      }
    }
    

    这似乎有点类似于applying different templates to the same widget 的解决方案。

    【讨论】:

    • Jason 是正确的,@UiTemplate 注释位于 UiBinder 派生接口上,而不是包含 Composite 类。除此之外,这使得有多个模板成为可能,并为每个模板声明不同的 UiBinder,如code.google.com/webtoolkit/doc/latest/…
    • initWidget 方法坚持使用 Template 类型的参数,否则会报语法错误: public FirstAppUI(final UiBinder binder) { initWidget(uiBinder.createAndBindUi(this));感谢您的链接,它看起来很相关,但不幸的是它不起作用。
    • 注意上面链接的GWT页面有错误,FirstAppUI构造函数的body应该是initWidget(binder.createAndBindUi(this))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 2016-09-05
    • 1970-01-01
    • 2012-07-26
    • 2014-07-27
    相关资源
    最近更新 更多