alejandro-du / crudui

Automatically generate CRUD-like Vaadin views for any Java Bean
https://vaadin.com/directory#!addon/crud-ui-add-on
Apache License 2.0
86 stars 54 forks source link

Method to set a Converter for a specific field #34

Closed adexerivera closed 5 years ago

adexerivera commented 6 years ago

I think it'd be a good idea to add a method to set a Converter for a specific field. This would allow converting price fields using a "currency converter", for example.

alejandro-du commented 5 years ago

@adexerivera: Sorry for the delayed response. The feature is now available on version 4.0.0 which requires Vaadin 14.0.2 or later. Here's a usage example:

formFactory.setConverter("salary", new Converter<String, BigDecimal>() {
    @Override
    public Result<BigDecimal> convertToModel(String value, ValueContext valueContext) {
        return Result.ok(new BigDecimal(value)); // error handling omitted
    }

    @Override
    public String convertToPresentation(BigDecimal value, ValueContext valueContext) {
        return value.toPlainString();
    }
});
adexerivera commented 5 years ago

@alejandro-du great, and thank you very much, now I just need to migrate my applications to Vaadin 14