具有可选参数的GWT UiConstructor [英] GWT UiConstructor with optional parameters

查看:55
本文介绍了具有可选参数的GWT UiConstructor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个带有4个参数的自定义窗口小部件.这些参数之一是可选的. 如果我们在U​​iBinder中使用小部件并忽略可选字段,则会引发错误.

We have a custom widget with 4 parameters. One of these parameters is optional. If we use the widget in UiBinder and omit the optional field an error is thrown.

例如

MyWidget(String arg1, String arg2, String arg3) {
  ...
}

如果我在UiBinder文件中编写

If in the UiBinder file I write

...
<b:MyWidget arg1="sdfsd" arg2="fsdgds" arg3="ertlkj">
...

如果我写

...
<b:MyWidget arg1="sdfsd" arg2="fsdgds">
...

然后发生以下错误:

[ERROR] <MyWidget arg1="sdfsd" arg2="fsdgds"> missing required attribute(s): arg3:     <b:MyWidget arg1="sdfsd" arg2="fsdgds">

有什么方法可以定义可选参数?

Is there any way to define optional arguments?

推荐答案

不管是好是坏,这不是UiBinder的设计方式.您只能指定一个@UiConstructor,UiBinder将始终使用该构造函数.

For better or worse, no - this is how UiBinder is designed. You can only designate one @UiConstructor, and UiBinder will always use that constructor.

如果可能,不要使它们成为构造函数参数,而要使它们成为setter.如果存在arg3属性,则可以选择调用setArg3()方法,而不是尝试在构造函数之间切换.

If possible, instead of making them constructor arguments, make them setters. The setArg3() method will be optionally called if the arg3 attribute is present, rather than trying to switch between constructors.

这篇关于具有可选参数的GWT UiConstructor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆