vaadin-component-factory / combo-box-light

Light ComboBox without lazy loading feature
Other
0 stars 1 forks source link

CBL only checks for object equality on "valid value" check #1

Closed stefanuebe closed 1 week ago

stefanuebe commented 2 weeks ago

The CBL does not take the data provider's getId() method into account nor does it provide any similar possibility to change the way on how values are compared to items. This leads to the issue, that updated beans need to be provided as a fresh set of items to the CBL to allow setting a "similar" instance as a value.

This is for instance an issue, when using it in combination with Jpa Repositories, that create new object instances on update operations.

Therefore the request is, that the CBL's internal key mapper either takes the data provider getId() method into account or a respective delegation method to the key mappers setIdentifierGetter method is provided.

Thanks

stefanuebe commented 2 weeks ago

Workaround using Reflection (e.g. with Apache Commons FieldUtils)

try {
    KeyMapper<?> keyMapper = (KeyMapper<?>) FieldUtils.readField(this, "keyMapper", true);
    keyMapper.setIdentifierGetter(item -> item instanceof HasId ? ((HasId) item).getId() : item);
} catch (Throwable throwable) {
    throw new RuntimeException(throwable);
}
TatuLund commented 2 weeks ago

I think this could be copy paste error as the regular ComboBox had similar identifier problem as well: https://github.com/vaadin/flow-components/pull/6632/files

TatuLund commented 1 week ago

Fixed in version 2.0.0