OptionGroup default select fails

Hi there,

I’ve got a small question.

I’m creating a OptionGroup like this:


OptionGroup searchPartyRadioButtonAcquiredInCommunity = new OptionGroup(TM.get("search.party.acquired.community"));
searchPartyRadioButtonAcquiredInCommunity.addItem(TM.get("dialogbox.yes"));
searchPartyRadioButtonAcquiredInCommunity.addItem(TM.get("dialogbox.no"));
searchPartyRadioButtonAcquiredInCommunity.addListener((ValueChangeListener) this);
searchPartyRadioButtonAcquiredInCommunity.setImmediate(true);

and disabling it:

searchPartyRadioButtonAcquiredInCommunity.setEnabled(false);

Then I actually tried to preselect an item like this:


searchPartyRadioButtonAcquiredInCommunity.setValue(searchPartyRadioButtonAcquiredInCommunity.getItem(TM.get("dialogbox.no")));
searchPartyRadioButtonAcquiredInCommunity.select(TM.get("dialogbox.no"));

But it didn’t do anything. When I did the following it did set my default value:

searchPartyRadioButtonAcquiredInCommunity.setNullSelectionItemId(TM.get("dialogbox.no"));

But when I try to retrieve the selected option it just gives me null.

searchPartyRadioButtonAcquiredInCommunity.getValue()

I tried adding

searchPartyRadioButtonAcquiredInCommunity.setValue(searchPartyRadioButtonAcquiredInCommunity.getItem(TM.get("dialogbox.no")));
searchPartyRadioButtonAcquiredInCommunity.select(TM.get("dialogbox.no"));

How can I preselect an option in the OptionGroup so that Vaadin knows that this item is also be the selected item?

Thanks already.

Use the item id, not the item for setValue or select and it should work.

Currently I’m doing it following Artur Signell instructions (using .select() with the ItemId I got after adding the offending option to the option group) and it selects nothing…

Ok, I got it wrong. the .addItem(“My item”) method I’m using actually returns an Item, not an ItemId.

Anyway, after getting it and trying .setValue(myNewItem) it won’t select anything, either.

The only thing that selectes the item is doing a .select(“Same string I used when adding the item”), but to my understanding the method above should work.