OptionGroup readonly+disabled problem

Im currently experiencing some problems with a OptionGroup im trying to use to be able to select multiple choices for my model. I got a model which I create a Form for using a FormFieldFactory, I got 3 properties on this model, name, description and a set of tags.

  • Model class -
String name
String description
Set<MyTagObject> tags

FormFieldFactory creates normal text fields for name and description and these work like they should so I created a multiselect optiongroup for the tags. As I think this is the best way to select these instead of ctrl/shift click within a list.

In the FormFieldFactory I first retrieve all available tags and store them in a list sorted. And then do the following:

final OptionGroup field = new OptionGroup("tags");
field.setMultiSelect(true);

for (final MyTagObject tag : tags)
{
  field.addItem(tag);
  field.setItemCaption(tag.caption());
}

Everything renders like it should the ordering of items, captions, the option group label and even the existing tags are checked when loading a existing model from the database.

But the optiongroup is readonly:

<div class="v-select-optiongroup v-readonly" style="">

and all options are disabled:

<span class="v-checkbox v-select-option v-checkbox-disabled v-disabled">
  <input type="checkbox" value="on" id="gwt-uid-15" tabindex="0" disabled=""><label for="gwt-uid-15">Tag 1</label>
</span>

I have tried forcing the field to be enabled and not readonly and setting each item as enabled with:

field.setEnabled(true);
field.setReadOnly(false);

and in the loop:

this.setItemEnabled(tag, true);

but nothing changes. So any help would be appriciated.

Same is happening to me…any clues?

Are you using a BeanItem? If so, does your bean have a setter for tags? BeanItem uses reflection to find getters and setters using standard Java naming conventions. If only a getter is found, the property is treated as read-only.

I went with a different solution using another type of component which wasn’t as good looking and probably not as stable solution but did work for me. Because Java Collections are mutable we don’t usually add setters for them as it isn’t needed.

So the suggested solution by Marcus Hellberg to have a setter for the collection will probably work.

I think we have the same problem, but using a List as input to setOptions() - this worked with vaadin 7.3.x but started being broken in 7.4
edit: sorry - setOptions() does not exist - that was some of our own wrapping - we call addItem() with a string.

Got it, we were using BeanFieldGroup, and calling fg.bind(optionGroup, “XXXX”) - on our data itemDataSource within the BeanFieldGroup, we had a public getXXXX() but the corresponding setXXXX() method was protected, and thus vaadins BeanFieldMagic made the optiongroup readonly.

So, since that is now the behavior (and it makes sense) we just made our setter public and now it works again.