Vaadin 8 validation using binder

hi, please help me for vaadin 8 validation using binder.

I am using pojo having fields like name, [b]
countryCode, mobile, email etc…

countryCode is a combobox of other bean/Pojo which is SystemCountry (this bean have id and country name fields)

now while applying validation usin binder of User pojo how can I apply validation on for countryCode (combobox field)

country code field initialised as
ComboBox countryCode = new ComboBox<>();

Provided values as,
countryCode.setItems(systemCountries); //list of system country provided

//Trying validation like
.withValidator(str → str == null || “”.equals(str), “Please select country”)
bind(User::getCountryCode, User::setCountryCode); // This line doesn’t accept User country code variable

and if I commit bind(User::getCountryCode, User::setCountryCode); this line while loading form it thorwing error like below,

java.lang.IllegalStateException: Property type ‘java.lang.String’ doesn’t match the field type ‘com.enovate.client.core.pojo.SystemCountry’. Binding should be configured manually using converter.
at$$Lambda$6165/1444034637.apply(Unknown Source)

please help me in same case. how can I implement or where I am wrong?

Exactly as what the exception says, you need a converter to convert countryCode ↔ SystemCountry. So it should be sth like

binder.forField(countryCode) .withValidator(str -> str == null || "".equals(str), "Please select country") .withConverter(SystemCountry::toContryCode, SystemCountry::fromContryCode) .bind(User::getCountryCode, User::setCountryCode); You need to implement two new methods in SystemCountry, to convert to and from countryCode.

Thanks it is fixed.