Vaadin8 comboBox: how to manage code and a description list

I have a bean


class MyBean {
Integer code;
String name
Integer typeCode;
}


MyBean myBean ;

and a list with types descriptions

[color=#0000FF]
class TypeDescription {
Integer typeCode;
String typeDescription;
}

List listrOfTypesDescriptions
[/color]

  • in the form, the comboBox must show list of types (listrOfTypesDescriptions)
  • and the type selected must be stored in the field typeCode of my object (Integer myBean.typeCode )

I defines ComboBox Type : TypeDescription


protected ComboBox cbxType;

and assign to ComboBox a list of TypeDescription


cbxType.setItems(listrOfTypesDescriptions)


how I bind ComboBox to bean attribute typeCode?

  • ComboBox Type is TypeDescription
  • typeCode type is Integer

binding generate error

[color=#0000FF]
Binder binder = new Binder<>(MyBean .class);

binder.forField(“type”)
.bind( MyBean ::getType, MyBean ::setType));
[/color]

becouse ComboBox Type is TypeDescription

thanks for any help

Hi,

A couple of thoughts:

  • You can use
    .withConverter
    to define an int (typecode) ↔ TypeDescription Converter
  • You don’t
    need
    to use method references like MyBean::getType and ::setType in
    bind()
    , you can also create the getter and setter manually, for example with lambda expressions

-Olli