【问题标题】:UiBinder custom widget with parameterized constructor带有参数化构造函数的 UiBinder 自定义小部件
【发布时间】:2011-10-09 05:53:07
【问题描述】:

假设我们有一个使用 UiBinder 声明的自定义小部件,并且它需要在其构造函数中包含一些参数。当我在 ui.xml 中声明它时,如何才能提供这些参数?

那是我有一个

CustomWidget(int param1, int param2)

当我将它添加到 ui.xml 时,我需要能够做到:

...

xmlns:my="urn:import:...">

<g:Container>
 <my:CustomWidget param1="1" param2="arg2"/>
</g:Container>

【问题讨论】:

    标签: gwt uibinder


    【解决方案1】:

    在你的构造函数上使用@UiConstructor

    @UiConstructor
    CustomWidget(int param1, int param2)
    

    查看文档:http://code.google.com/webtoolkit/doc/latest/DevGuideUiBinder.html#Using_a_widget

    【讨论】:

    • 首先感谢,这就是解决方案。但是为什么不能在多个构造函数中添加@Uiconstructor(重载)?那么 gwt 小部件如何在 uibinder 中提供几个参数以在声明时传递而不是全部?
    • 我的意思是我可以声明 但使用 @UiConstructor 我必须添加所有论据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-22
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多