Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically adding multiple GWT RadioButton groups

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?

like image 900
jwien001 Avatar asked Oct 12 '22 08:10

jwien001


1 Answers

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.

like image 75
Chris Lercher Avatar answered Oct 14 '22 04:10

Chris Lercher