I am so confused about how to use OptionGroup (radio buttons).
I know how to hook up a String values in a domain object to a BeanItem, and from there set the properties of the BeanItem as the data source for various TextField objects on a layout.
[DomainObject member variables]
↔ [JavaBean getter-setter conventions or BeanInfo]
↔ [BeanItem properties]
↔ [TextFields data sources]
But I can’t seem to wrap my head around how to do the same with the Select widgets such as OptionGroup.
What I want is 3 radio buttons that map to an integer value:
[font=Courier New]
( ) Yes
( ) No
( o ) Not yet answered
[/font]
Those radio buttons should map to an Integer property on my BeanItem, where:
Yes = 1
No = 0
Not yet answered = -1
Can someone give me a clue about the easy way to do this? I’ve found some hard ways.
Thanks to Éric for the suggestion to consider using an enum. (I assume he meant an
enum rather than
Enumeration .) I did indeed learn how to use an enum to back an OptionGroup (radio buttons). Works rather well.
See
my answer on StackOverflow for explanation and a couple of complete example apps showing how to populate an OptionGroup with an enum.