HasValue.getValue() does not call converter

I have this simple view:

@Route("demo")
public class DemoView extends Div {

    public DemoView() {
        Binder<Employee> binder = new Binder<>(Employee.class);
        TextField nameField = new TextField();
        binder.bind(nameField, "name");

        add(nameField);

        TextField salaryField = new TextField();
        binder.forField(salaryField)
                .withConverter(new StringToBigDecimalConverter("Not a number!"))
                .bind("salary");

        add(salaryField);

        binder.setBean(new Employee("Kaspar", new BigDecimal("80000"), LocalDate.of(1990, 05, 01)));

        Button button = new Button("Klick mich");
        button.addClickListener(event -> {
            String value = salaryField.getValue();

            System.out.println(value);
        });

        add(button);
    }
}

The salary field has a StringToBigDecimalConverter but when salaryField.getValue() is called a formatted String (e.g. 80,000) is returned. I would assume that getValue should return a BigDecimal.

Hi Simon

The StringToBigDecimalConverter is not added to the TextField, but to the binding of the field to the binder.
This means that when you call getValue() on the TextField itself, you will get the String value that the textfield holds at the moment. Only when the binder wants to use the value to set the property on the bean it uses the converter.

PS: I like the name of your Employee :slight_smile:

Ok I see. Is there a way to have the Converter converting the value to the model type when calling getValue()?