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.
For example
MyWidget(String arg1, String arg2, String arg3) {
...
}
If in the UiBinder file I write
...
<b:MyWidget arg1="sdfsd" arg2="fsdgds" arg3="ertlkj">
...
If I write
...
<b:MyWidget arg1="sdfsd" arg2="fsdgds">
...
Then the following error occurs:
[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?
For better or worse, no - this is how UiBinder is designed. You can only designate one @UiConstructor
, and UiBinder will always use that constructor.
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.