我正在尝试创建自定义TabLayoutPanel
扩展程序,我的代码如下:
public class ExpandableTabLayoutPanel extends TabLayoutPanel {
@UiConstructor
public ExpandableTabLayoutPanel(double barHeight, Unit barUnit) {
super(barHeight, barUnit);
addExpandableBehaviour();
}
private addExpandableBehaviour(){
//...
}
}
在这里,我从UIBinder调用它:
<a:ExpandableTabLayoutPanel barHeight="20" barUnit="PX">
<a:tab>
<a:header>header</a:header>
<a:AdvancedRichTextArea styleName="{style.area}" ui:field="area"/>
</a:tab>
</a:ExpandableTabLayoutPanel>
(即使我没有在我的a:tab
/ a:header
中定义标签和标头,我也会被错误消息强制使用g:tab
/ g:header
而不是a:
/ @UiConstructor
{1}}包/工作区,但这可能不是问题)
如果在列表中的ExpandableTabLayoutPanel上存在[ERROR] [gwtreproduce] - <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> missing required attribute(s): arg1 barHeight Element <a:ExpandableTabLayoutPanel barHeight='20' barUnit='PX'> (:13)
注释,我会收到奇怪的错误:
@UiConstructor
当我禁用[ERROR] [gwtreproduce] - Errors in 'generated://E6338B946DFB2D28988DA492134093C7/reproduce/client/TestView_TestViewUiBinderImpl.java' : [ERROR] [gwtreproduce] - Line 33: Type mismatch: cannot convert from TabLayoutPanel to ExpandableTabLayoutPanel
时,我的错误甚至更加奇怪:
TabLayoutPanel
扩展TabLayoutPanel我做错了什么?
并提出问题:{{1}}构造函数如何不用@UiConstructor注释,并且可以在UiBinder中使用(UiBinder如何知道要调用哪个构造函数)?
答案 0 :(得分:0)
对于你的问题:你必须添加(provided = true)到你的小部件的UiField注释。然后在代码中,自己设置实例,之前 createAndBindUi()调用如下:
class Whaoo extends Composite{
/* with 'provided', UiBinder don't call any constructor */
@UiField(provided = true)
final Great foo;
interface WhaooUiBinder extends
UiBinder<Widget, Whaoo> {}
private static WhaooUiBinder uiBinder =
GWT.create(WhaooUiBinder.class);
public Whaoo() {
// initialize "provided" before createAndBindUi call
foo = new Great(String bar, int pouet);
initWidget(uiBinder.createAndBindUi(this));
}
}