Select default on OptionGroup

Hi,

I have a problem with the preselect of a radiobutton (optionGroup).
I create a BeanItemContainer and fill it with some object (just a simple object containing a key and a value).
Next I create an Optiongroup with this container. The strings on the screen are correct, the value on the form is correct (after selecting a radiobutton), but I can’t preselect one.
This is my code:

BeanItemContainer<KeyValueWrapper> enquiryTypesContainer = new BeanItemContainer<KeyValueWrapper>(KeyValueWrapper.class);
enquiryTypesContainer.addItem(new KeyValueWrapper("1", "label1"));
enquiryTypesContainer.addItem(new KeyValueWrapper("2", "label2"));

OptionGroup enquiryTypes = new OptionGroup(null, enquiryTypesContainer);
enquiryTypes.setItemCaptionMode(Select.ITEM_CAPTION_MODE_ITEM);
enquiryTypes.setItemCaptionPropertyId("value");
enquiryTypes.select(enquiryTypesContainer.firstItemId());

enquiryTypes.setNullSelectionAllowed(false);
    enquiryTypes.setPropertyDataSource(new MethodProperty(getForm(), "enquiryType"));

All I want is the first one to be selected on screen entry…
Any suggestions on how to solve this? I already tried useing de wrapper methods getValue and getKey on the containerItems.

Thanks in advance,
Jolanda

Nobody any suggestions???

Jolanda

I’d probably try to get enquiryTypes.getItemIds().iterator(), and just simply get the first item from that iterator. Remember to check whether the container is empty or not, to avoid exceptions.

Hi,

Try doing
enquiryTypes.select(enquiryTypesContainer.firstItemId())

after
setting the datasource.
This could also be valuable information (if I remember correctly): BeanItemContainer uses the actual bean as itemId, so you can say e.g
optionGroup.setValue(someBean)
.

Best Regards,
Marc