【问题标题】:gwt custom widget with child elements configuration in UIBinder (like CustomButton)在 UIBinder 中具有子元素配置的 gwt 自定义小部件(如 CustomButton)
【发布时间】:2012-01-12 14:42:36
【问题描述】:

我面临一个创建自定义小部件的任务,它具有容器行为——内部有 3 个面板。 我想以一般的 UIBinder 方式使用它,比如CustomButton

 <u:MyWidget>
   <u:image><g:Image .../></u:image>
   <u:mainContent><g:Panel.../></u:mainContent>
 </u:MyWinget>

是否可以以某种方式定义自定义子元素,或者它可能是 UIBuilder 中预定义的东西?

提前致谢

【问题讨论】:

    标签: gwt uibinder


    【解决方案1】:

    正确的做法是使用UiChild注解。

    public class MyWidget extends Composite {
      public MyWidget() {
        // ...
      }
    
      @UiChild( tagname = "image" )
      void addImage(Image image) {
        // ...
      } 
    
      @UiChild( tagname = "mainContent" )
      void addMainContent(Widget contentWidget) {
      }
    }
    

    【讨论】:

    • @Thomas - 但是一般来说你是怎么做的呢?例如,如果所有子面板都实现了 myInnerPanel,我如何访问该子面板?文档说这个标签名称必须与方法名称完全匹配。有解决办法吗?
    • 好的,开始工作了。只要我的通用类型,比如 MyAbstractWidget 由“customtag”标签的子级扩展,那么在@UiChild 方法中,我可以毫无问题地从 Widget 向上转换为 MyAbstractWidget。这样@UiChild 方法和父小部件就可以处理任何正确形成的“customtag”未来子级。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 2012-08-04
    • 1970-01-01
    • 2011-04-25
    • 1970-01-01
    • 2021-07-15
    • 2011-07-20
    相关资源
    最近更新 更多