带参数的 GWT UiConstructor,类没有适当的 setter 方法

发布于 2024-10-20 11:37:29 字数 1417 浏览 6 评论 0原文

我想实现一个自定义 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 文件中使用了自定义复合小部件 但是,当我在浏览器中启动并测试 Web 应用程序时,出现以下错误:

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

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

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

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

希望我足够清楚...请尽快阅读!

I'd like to implement a custom TabLayoutPanel which would automatically setup the tab itself when adding a widget (with custom actions such as closing the tab, etc).

I created a CustomTabPanel.ui.xml along with a CustomTabPanel.java. The UI design simply embeds a TabLayoutPanel and the code part exposes some functions that I need.
I also have a constructor that takes the same 2 arguments as the TabLayoutPanel, that I would like to pass in UI design mode just as I do with the plain TabLayoutPanel.
It looks like this

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));
    }

I use the custom composite widget in another .ui.xml file
But then, when I launch and test the web app in my browser, I get the following error:

Class CustomTabPanel has no appropriate setBarUnit() method.
Element <my:ClosableTabPanel barHeight='2' barUnit='EM' ui:field='closablepanel'>

I followed the instructions read on http://code.google.com/intl/fr/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_a_widget to make this. I think I have missed something but I can't find out what it is.

Also I tried before to use inheritance by creating a derived class ExtendedTabLayoutPanel extends TabLayoutPanel{...} and implementing the constructor with the arguments. This gives me, at runtime, another error :

Line xx: Type mismatch: cannot convert from TabLayoutPanel to ExtendedTabLayoutPanel

Hope I'm clear enough... Read you soon!

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

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

发布评论

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

评论(2

一绘本一梦想 2024-10-27 11:37:29

我也遇到了同样的问题。事实证明,参数的顺序在某种程度上很重要;请参阅 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>

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

I was having the same problem. It turns out that the order of the arguments is important somehow; see http://code.google.com/p/google-web-toolkit/issues/detail?id=5272

When you have the order right, you don't need to worry about converting the enum. I now have this:

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

... and in my .ui.xml file:

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

I wonder if the required order of arguments is robust across different deployments?

人海汹涌 2024-10-27 11:37:29

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

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

Your issue might have to do with the fact that com.google.gwt.dom.client.Style.Unit is an enumeration. An alternative approach that should solve the problem is to change barUnit to type string and then use Unit.valueOf(barUnit) to retrieve the appropriate enumeration value. This also give you the ability to properly error check the unit name being passed.

As for the issue with inheritance in UiBinder this is actually a known issue that has been patched but hasn't been officially added to GWT.

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