How to properly bind a string combobox to a integer value?

t to convertHere’s what I’m trying to do:

binder.forField(comboRegime).withConverter(
                // The logic would follow something like this.
                r -> {
                    switch (comboRegime.getValue()) {
                        case "1 - Simples Nacional": {
                            return 1;
                        }
                            break;
                        case "2 - Lucro Presumido": {
                            return 2;
                        }
                            break;
                        case "3 - Lucro Real": {
                            return 3;
                        }
                            break;
                        default: {
                            return 0;
                        }
                            break;
                    }
                }).bind(ClienteModel::getRegime, ClienteModel::setRegime);```
The switch statement is what I want to convert the combobox value to. I read the docs but found no examples of how to acomplish that.

Hello again! I was reading the wrong docs. sorry!
Here is the solution:

First, i create a custom coverter class:

private class ConverterComboRegime implements Converter<String, Integer> {
        @Override
        public Result<Integer> convertToModel(
                String fieldValue, ValueContext context) {
            try {
                switch (fieldValue) {
                    case "1 - Simples Nacional": {
                        return Result.ok(1);
                    }
                    case "2 - Lucro Presumido": {
                        return Result.ok(2);
                    }
                    case "3 - Lucro Real": {
                        return Result.ok(3);
                    }
                    default: {
                        return Result.ok(0);
                    }
                }
            } catch (NumberFormatException e) {
                return Result.error("Enter a number");
            }
        }

        @Override
        public String convertToPresentation(
                Integer integer, ValueContext context) {
            //You need to also do the reverse conversion if you want to call binder.readBean()
            switch (integer) {
                case 1: {
                    return "1 - Simples Nacional";
                }
                case 2: {
                    return "2 - Lucro Presumido";
                }
                case 3: {
                    return "3 - Lucro Real";
                }
                default: {
                    return null;
                }
            }
        }
    }```

Then, i just use the class on the withConverter bind:

binder.forField(comboRegime).withConverter(new ConverterComboRegime()).bind(ClienteModel::getRegime,
                ClienteModel::setRegime);```

Docs:https://vaadin.com/docs/latest/binding-data/components-binder-validation/#converting-user-input