Binder for ComboBox<Object>

Hi everyone,

I have a question about binding. I have a ComboBox of object person and i am only displaying the “name” property of this object. Can i bind the “id” of this person in my binder? My binder is of type Map.

//binder of type map
Binder<Map<String, String>> binder = new Binder<>();
Map<String, String> bean = new HashMap<>();
binder.setBean(bean);

//text area
TextArea taComment = new TextArea("Comment");
taComment.setId("comment");
taComment.setValueChangeMode(ValueChangeMode.EAGER);
binder.forField(taComment)
	.withValidator(new StringLengthValidator("Please add comment using between 1 and 250 symbols", 1, 250))
	.bind(data -> data.get(taComment.getId().get()), (data, value) -> data.put(taComment.getId().get(), value));

//combo box of person -> displaying only the names, want to bind the id of this Person to the binder
ComboBox<Person> cbPerson = new ComboBox<>("Select Person");
//cbPerson.setItems(...)
cbPerson.setId("person");
cbPerson.setItemLabelGenerator(Person::getName);
binder.forField(cbPerson)
    .asRequired("Please select person")
    .withConverter(..........)
    .bind(.........);
	
	
binder.getBean().get("comment") -> text you entered in the taComment
binder.getBean().get("person") -> return the Id of that person

Best Regards,
Vladislav

It’s possible, but that looks like an overly complicated way of doing things. I’d recommend doing the binding with regular Java Beans first and the conversion to a Map as a secondary step.