In my application I have a panel of widgets (all the same type of widget), and buttons that allow the user to add and remove widgets to the panel. Inside each of the widgets is a GWT RadioButton group. The widget uses the GWT UiBinder, and so in my ui.xml file I give each RadioButton a group name so that they will link together.
This becomes a problem, however, when 2 or more of this widget are added to the panel, because all the RadioButtons in all of the widgets have the same group name. I want each RadioButton group in each of the widgets to be independent of the others. How can I do this?
You can introduce a groupName parameter to your widget constructor, and then use @UiFactory to build the RadioButtons:
private String groupName;
public MyWidget(String groupName) {
this.groupName = groupName;
initWidget(uiBinder.createAndBindUi(this));
}
@UiFactory
RadioButton makeRadioButton() {
return new RadioButton(groupName);
}
makeRadioButton()
will be called automatically for all your <g:RadioButton>
s you use in the UiBinder xml file.
Now you can create each of these widgets with a different radio group name dynamically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With