【问题标题】:GWT - Apply different XML templates to the same widgetGWT - 将不同的 XML 模板应用到同一个小部件
【发布时间】:2012-10-03 21:55:15
【问题描述】:

为了减少一些重复的代码/类,我尝试为仅 1 个所有者类使用多个 XML 模板。 official GWT guide 指出了如何做到这一点。

   public class FooPickerDisplay extends Composite{
     @UiTemplate("RedFooPicker.ui.xml")
     interface RedBinder extends UiBinder<Widget, FooPickerDisplay> {}
     private static RedBinder redBinder = GWT.create(RedBinder.class);

     @UiTemplate("BlueFooPicker.ui.xml")
     interface BlueBinder extends UiBinder<Widget, FooPickerDisplay> {}
     private static BlueBinder blueBinder = GWT.create(BlueBinder.class);

     @UiField Button button1;
   }

'@UiField'会导致编译错误,提示“Field button1 has no对应的field in template file BlueFooPicker.ui.xml”

我的 RedFooPicker.ui.xml 和 BlueFooPicker.ui.xml 的内容完全不同,所以 RedFooPicker.ui.xml 中有 UiField="button1" 但 BlueFooPicker.ui.xml 中没有 button1。

所以我的问题是,是否有任何方法可以为同一个所有者类使用具有完全不同内容的多个 XML 模板而不会导致此类错误?

【问题讨论】:

    标签: java templates gwt uibinder


    【解决方案1】:

    不,每个UiBinder 必须作用于不同的所有者类。但是,您可以轻松地为 UiBinder 之一创建内部类。文档中的示例是关于使用其中一种,而不是同时使用两种。

    顺便说一句,为了减少重复,您最好尝试将事物抽象为可重用的小部件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-10
      • 2022-01-22
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多