How to create option group

Toolkit demo has Form with option-group but there is no sample code available.

How do I create option group to form or option group without form?

You can create option group with Select-component, just set style “optiongroup”.
Example:


Select s = new Select("Options");
s.setStyle("optiongroup");
s.addItem("Option 1");
s.addItem("Option 2");
s.addItem("Option 3");
someLayout.addComponent(s);

hi,
I created BeanItemContainer and add it to constructor of OptionGroup



public class StateBean {

	private boolean enabled;
	private String name;
...}
	states = new BeanItemContainer<StateBean>(StateBean.class);
	states.addBean(new StateBean("State 1", true));
	states.addBean(new StateBean("State 2", false));
	states.addBean(new StateBean("State 3", true));

	flowState = new OptionGroup("Current flow state", states);
	flowState.setMultiSelect(true);
	flowState.setNullSelectionAllowed(true);
	flowState.setImmediate(true); 

The result is 3 unchecked checkboxes, but with correct names from created beans.
How can i tell to OptionGroup that checkboxes should be synchronized with
enabled
property of StateBean class?

Thanks

Additional more straightforward question.

How can I initialize the values (checked/unchecked) of the checkboxes in the OptionGroup.?
It should be simple!! But I can’t find the way :frowning:


List<String> cities = Arrays.asList(new String[]{
    "Berlin", "Brussels", "Helsinki", "Madrid", "Oslo", "Paris",
    "Stockholm"});
     OptionGroup optionGroup = new OptionGroup("Please select cities", cities);

    optionGroup.setMultiSelect(true);
    optionGroup.setValue(Arrays.asList(new String[]{ "Berlin", "Brussels", "Helsinki", "Madrid", "Stockholm"}))

that’s how