Get selected values of multiple optionGroups

Hey,

i add items of a array to a multiple optiongroup:

optionGroup = new OptionGroup();
optionGroup.setMultiSelect(true);
optionGroup.setNullSelectionAllowed(true);
optionGroup.setImmediate(true);
for(int a=0; a<array.length; a++) {
     optionGroup.addItem(array[a]
);
}

so it works.

now, i want to get all values of the selected items separately by a ValueChangeListener.
i can not use “optionGroup.getValue()” because its just a string like "[option1, option2]
" - thats bad.
I think i need “optionGroup.getItemIds()”, but how it works? how works the iterator?

optionGroup.addListener(new Property.ValueChangeListener() {
     private static final long serialVersionUID = 1L;
     @Override
     public void valueChange(ValueChangeEvent event) {
            for(int a=0; a<optionGroup.getItemIds().size(); a++) {                             
                      ???
            }                        
     }
});

Thanks for help.

Thats the solution:


Collection selectedItems = (Collection) optionGroup.getValue();
// or
Collection selectedItems = (Collection) event.getProperty().getValue();

Iterator iterator = selectedItems.iterator();
while (iterator.hasNext()) {
     System.out.println(iterator.next());                            
}