Vaadin 21: re-translate column with ItemLabelGenerator on locale change

316 views Asked by At

In a Vaadin 21 application I've got a grid with a column that represents an enum. Translation is done like this:

Column<MyDomainClass> myColumn = grid.addColumn(new TextRenderer<MyDomainClass>(new ItemLabelGenerator<MyDomainClass>() {
    @Override
    public String apply(MyDomainClass gridItem) {
        String i18nKey = gridItem.getMyEnumAttribute().name();
        return getTranslation(i18nKey);
    }
}

This translates the enum values in the column when the view loads.

I just added a combobox to change the locale and register all components with labels, ... by implementing the interface LocaleChangeObserver like this:

@Override
public void localeChange(LocaleChangeEvent localeChangeEvent) {
    // These two work fine
    myTextfield.setLabel(getTranslation(textfieldI18nKey));
    myCombobox.setLabel(getTranslation(comboboxI18nKey));
    [...]
    // This one feels a little strange but works
    myCombobox.setItemLabelGenerator(myCombobox.getItemLabelGenerator());
    // And for this I don't know how to do it
    myColumn.reTranslateAllItems();
}

Smell Re-Setting the ItemLabelGenerator at the combobox again feels a little strange, but works.

Question How can I retranslate all items in the column? So what's the right substitution for myColumn.reTranslateAllItems() (see above)?

0

There are 0 answers