Empty captions in OptionGroup


Trying to use a OptionGroup here but can’t manage to set an explicit caption. If I do this (in Scala):

val gender = new OptionGroup(“Sukupuoli”)
val m = gender.addItem(1)
val f = gender.addItem(0)
gender.setItemCaption(m, “MIES”)
gender.setItemCaption(f, “NAINEN”)

[/code]I get the radio buttons but there is no caption next to them. If I remove the explicit setItemCaption call (line 3) then I get a 1 and 0 next to the buttons. Is this a bug or how should this work? It seems to work if I use the parameterless call to addItem(), but I can’t use generated IDs in my data model. Using Vaadin 7.0.4. Thanks!


you’re using the items in place of itemIds. Try this:

gender.setItemCaption(0, "MIES")
gender.setItemCaption(1, "NAINEN")

Edit: There also seems to be an Item ref in your select call instead of an itemId ref.

Argh of course. Silly me! Thank you Sir!!!

Now I could argue that this is a bit misleading, since the addItem() returns an itemId that can be used but the addItem(Object) returns the item, not the itemId. Maybe the addItem() could be renamed addItemId() or addGeneratedItemId() or something. Anyway, thanks again!