【问题标题】:GWT UiConstructor with arguments, class has no appropriate setter method带参数的 GWT UiConstructor,类没有适当的设置方法
【发布时间】:2011-03-07 18:03:07
【问题描述】:

我想实现一个自定义的 TabLayoutPanel,它会在添加小部件时自动设置选项卡本身(使用自定义操作,例如关闭选项卡等)。

我创建了一个 CustomTabPanel.ui.xml 和一个 CustomTabPanel.java。 UI 设计简单地嵌入了一个 TabLayoutPanel,代码部分公开了一些我需要的功能。 我还有一个构造函数,它采用与 TabLayoutPanel 相同的 2 个参数,我想在 UI 设计模式中传递它,就像我对普通 TabLayoutPanel 所做的那样。 看起来是这样的

public class CustomTabPanel extends Composite{
    /* ... here all the uiBinder things
       already written by my eclipse plugin */

    @UiField(provided=true)
    TabLayoutPanel tabPanel;

    public @UiConstructor CustomTabPanel(double barHeight, Unit barUnit){
        tabPanel = new TabLayoutPanl(barHeight, barUnit);
        initWidget(uiBinder.creatAndBindUi(this));
    }

我在另一个 .ui.xml 文件中使用自定义复合小部件 但是,当我在浏览器中启动和测试网络应用程序时,我收到以下错误:

类 CustomTabPanel 没有合适的 setBarUnit() 方法。 元素

我按照http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_a_widget 上的说明进行操作。我想我错过了一些东西,但我不知道它是什么。

我之前也尝试过通过创建派生的class ExtendedTabLayoutPanel extends TabLayoutPanel{...} 并使用参数实现构造函数来使用继承。这在运行时给了我另一个错误:

第 xx 行:类型不匹配:无法从 TabLayoutPanel 转换为 ExtendedTabLayoutPanel

希望我说得够清楚了……快读!

【问题讨论】:

    标签: xml gwt layout constructor uibinder


    【解决方案1】:

    我遇到了同样的问题。事实证明,论点的顺序在某种程度上很重要。见http://code.google.com/p/google-web-toolkit/issues/detail?id=5272

    当您有正确的顺序时,您无需担心转换枚举。我现在有这个:

    public @UiConstructor FancyTabLayoutPanel(Unit barUnit, double barHeight) {...}
    

    ...在我的 .ui.xml 文件中:

    <v:FancyTabLayoutPanel barUnit="EM" barHeight="2.0"></v:FancyTabLayoutPanel>
    

    我想知道所需的参数顺序在不同的部署中是否可靠?

    【讨论】:

      【解决方案2】:

      您的问题可能与 com.google.gwt.dom.client.Style.Unit 是一个枚举这一事实有关。应该解决该问题的另一种方法是将 barUnit 更改为字符串类型,然后使用 Unit.valueOf(barUnit) 检索适当的枚举值。这也使您能够正确错误检查正在传递的单元名称。

      至于 UiBinder 中的继承问题,这实际上是一个 known issue 已修补但尚未正式添加到 GWT。

      【讨论】:

      • 即使将单位作为字符串传递,错误仍然存​​在。虽然,当作为 Unit 或 String 传递时它工作正常,但作为 FIRST 参数。似乎它与 z0r 所说的错误相符。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      相关资源
      最近更新 更多