Reputation: 947
I have the following situation. There are two combos on my UI form, one shows the list of vegetables and another one shows a list of fruits.
In my supporting view class I'd like to declare such methods:
@UiFactory
SimpleComboBox<Vegetable> createVegetablesCombo() {
return vegetables;
}
@UiFactory
SimpleComboBox<Fruit> createFruitsCombo() {
return fruits;
}
But it seems that GWT does not recognize parameterized returned types... Every time I get an error:
ERROR: Duplicate factory in class VegetablesAndFruitsView for type SimpleComboBox.
Is it possible to handle this case? Is there a good example of multiple comboboxes on one UI form?
Upvotes: 1
Views: 2092
Reputation: 18346
From the perspective of Java (not GWT, not UiBinder, but the Java language itself) at runtime there isn't a difference between SimpleComboBox<Vegetable>
and SimpleComboBox<Fruit>
. That said, this error is coming from UiBinder's code generation, which is looking for all @UiConstructor
methods, and using them to build things.
So what does UiBinder have to work with? From the UiBinder XML, there is no generics. The only way UiBinder could get this right is if you happen to have included a @UiField
entry in your class with the proper generics. This then would require @UiField
annotations any time there might be ambiguity like this, something GWT doesn't presently do.
What are you trying to achieve in this? You are returning a field (either vegetables
or fruits
) - why isn't that field just tagged as @UiField(provided=true)
? Then, whatever wiring you are doing to assign those fields can be used from UiBinder without the need for the @UiConstructor
methods at all.
@UiField(provided=true)
SimpleComboBox<Fruit> fruits;
//...
public MyWidget() {
fruits = new SimpleComboBox<Fruit>(...);
binder.createAndBind(this);
}
...
<form:SimpleComboBox ui:field="fruits" />
If this is just an over-simplification, and you actually plan on creating new objects in those methods, then consider passing an argument in, something like String type
, and returning a different SimpleComboBox<?>
based on the value. From your UiBinder xml, you could create the right thing like this:
<field:SimpleComboBox type="fruit" />
Upvotes: 3