Hello friends.
I ran into an issue the other day that I was a little confused about how to work around.
I have a VerticalLayout which implements a RadioButtonGroup using the following code:
RadioButtonGroup<String> radioGroup;
var leftPane = new VerticalLayout();
leftPane.setSizeFull();
leftPane.setWidth("555px");
leftPane.add(new H2("Site Automation!"));
radioGroup = GetRadioButtons.InitializeRadioButtons();
leftPane.add(GetRadioButtons.getRadioButtonLayout(radioGroup));
The GetRadioButtons class is as follows:
public class GetRadioButtons {
static RadioButtonGroup<String> InitializeRadioButtons(){
RadioButtonGroup<String> radioGroup = new RadioButtonGroup<>();
radioGroup.setLabel("Select an option to distribute");
radioGroup.setItems("Set 1", "Set 2", "Feed", "Add new set");
return radioGroup;
}
static Component getRadioButtonLayout(RadioButtonGroup<String> radioGroup){
var layout = new HorizontalLayout();
radioGroup.addValueChangeListener(e -> {
if (radioGroup.getValue().contains("Set")){
//Todo Fix
}
});
layout.add(radioGroup);
return layout;
}
}
The little bit in the middle of “GetRadioButtonLayout” is what I’m seeking to fix. The caller is static, but the verticalLayout is non-static (since the site needs to be used by (potentially) many people)I cannot directly call LeftPane.leftPane.add(ELEMENTS GO HERE)
Is the easiest way to remediate this by passing in the vertical layout to the getRadioButtonLayout method or am I missing something terribly basic?