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

Allow to use custom field provider not by property name but by property type #119

Closed flozano closed 1 year ago

flozano commented 1 year ago

I would like to centralize making all columns of a given type to be handled in a specific way. Currently it's allowed to set values for specific properties, only.

in AbstractAutoGeneratedCrudFormFactory:

    protected HasValueAndElement buildField(CrudFormConfiguration configuration, String property, Class<?> propertyType, T domainObject) throws InstantiationException, IllegalAccessException {
        HasValueAndElement<?, ?> field;
        FieldProvider<?, T> provider = (FieldProvider<?, T>) configuration.getFieldProviders().get(property);

        if (provider != null) {
            field = provider.buildField(domainObject);
        } else {
            Class<? extends HasValueAndElement<?, ?>> fieldType = configuration.getFieldTypes().get(property);
            if (fieldType != null) {
                field = fieldType.newInstance();
            } else {
                field = new DefaultFieldProvider(propertyType).buildField(domainObject);
            }
        }

it would be great if it was possible to override

                field = new DefaultFieldProvider(propertyType).buildField(domainObject);

by changing new DefaultFieldProvider(propertyType) to a new method getFieldProvider(propertyType) and make it overridable.

Or, is there any other better way to achieve this?

(Initially reported by mistake in https://github.com/vaadin/directory/issues/47)