Set String field from ValueCollectionDatasource


I’m sure I’m missing something simple, but I’m hoping this is possible.

I’ve got a String field and want to be able to select from a list of distinct values for that field from other records. I’ve created a ValueCollectionDatasource with the distinct query. I have a LookupField with the optionsDatasource set to that datasource and the captionProperty set to the name of the property set in the datasource. That displays the distinct list of values for that field correctly, but when I select one I receive an error:

“ConversionException: Unable to convert value of type com.haulmont.cuba.core.entity.KeyValueEntity to model type class java.lang.String. No converter is set and the types are not compatible.”

Also when opening an existing record, I receive an error:

“ClassCastException: java.lang.String cannot be cast to com.haulmont.cuba.core.entity.Entity”

Any suggestions would be appreciated.


Hi Steven,

A datasource always contains entities, in case of ValueCollectionDatasource it is KeyValueEntity. Even though you set a captionProperty for the LookupField, it affects only the representation of options, the result of the selection will be an entity instance anyway.

So you have to use setOptionsList() / setOptionsMap() methods of LookupField if you want a non-entity result value. You also don’t need an options datasource in this case, just load data via DataManager.

Thanks very much for the prompt reply. I knew I must have been going about it the wrong way.

However, it would be nice if it would work like that. I tried the same thing.