Usage of converters on comboboxes


I am currently trying to look at how converters are supposed to work on my combobox. On creation of my combobox I set a converter to convert from one datatype to another.

My question is when and for what methods does this conversion occur.

My situation:

I currently have a combobx with a converter on it. I also have a validator and a valueChangeListener on the combobox.

When the validators validate method is run the object parameter is the converted type. This is what I expect.

When the valueChangeListeners valueChange method is run the event.getProperty().getValue() is the original type (it is not converted). As a workaround to this I thought about ignoring that object and just getting the value from the combobox when the valueChange event is triggered. But when I do this it is also the original type.

Therefore when is the converter supposed to convert and how do I get the converted type in my valueChangeListener without having to convert it seperately?



Converters are used for converting between model type and Field presentation type. For converters to work most logically you need a property data source for your Field. Then the property data source value will be always model type and Field value will be presentation type. If you are not using data sources, to get the model type data from field you have to call getConvertedValue().

If you don’t feel like using data source you can as a workaround cast the Property.ValueChange event to AbstractField.ValueChangeEvent which extends Component.Event meaning that you can get the Field source and call getConvertedValue.

Hi, and thanks for taking the time to reply!

I am using a container, which presents item ids as UUIDs.
When I had no converter, validators on a combo box attached to such a container were called with a UUID argument. After I added a converter to convert UUIDs to a POJO the validator was now called with the POJO object.
However, the ValueChangeEvent was unaffected and still passed a UUID. I understand your workaround for casting to the AbstractField’s VCE, but you also say that this should only be necessary when not using a datasource?

The workaround is fine, but I’d like to understand further, or maybe help with a bug report if this is what it turns out to be. Or more likely, have I misunderstood somewhere?
Thanks, Dan.

Sorry for a delayed answer. I somehow missed your post. I hope you got this already working, but still here’s an answer.

The validators are always done for the model type. The value change of a Field gives a presentation type. AFAIK this is by design. If you want to have value change event containing a model type. value, you have to subscribe to a value change event from the data source Property.