maxTextLength doesn't work on generated Label columns

I placed a table on a form and added a generated column to it with maxTextLength=“30”:

<column id="flatList" caption="msg://flatList" sortable="false" width="300" maxTextLength="30"
 generator="generateFlatListCell"/>

generator:

public Component generateFlatListCell(VisitAssignment entity) {
    if (entity != null && entity.getVaFlats() != null && entity.getVaFlats().size() > 0) {
        Label label = componentsFactory.createComponent(Label.class);
        entity.getVaFlats().sort(Comparator.comparing(Flat::getFlOrder));
        StringBuilder stringBuilder = new StringBuilder();
        for (Flat flat: entity.getVaFlats())
            stringBuilder.append(stringBuilder.length() == 0 ? "" : ", ").append(flat.getFlNumber());
        label.setValue(stringBuilder.toString());
        return label;
    }
    return null;
}

But unexpectedly I got a super-wide column instead of short link. I had to implement a workaround with PopupView component:

public Component generateFlatListCell(VisitAssignment entity) {
    if (entity != null && entity.getVaFlats() != null && entity.getVaFlats().size() > 0) {
        TextArea label = componentsFactory.createComponent(TextArea.class);
        entity.getVaFlats().sort(Comparator.comparing(Flat::getFlOrder));
        StringBuilder stringBuilder = new StringBuilder();
        for (Flat flat: entity.getVaFlats())
            stringBuilder.append(stringBuilder.length() == 0 ? "" : ", ").append(flat.getFlNumber());
        String text = stringBuilder.toString();
        label.setValue(text);
        label.setRows(7);
        label.setColumns(30);
        label.setEditable(false);
        PopupView popupView = componentsFactory.createComponent(PopupView.class);
        popupView.setMinimizedValue(text.substring(0, Math.min(30,text.length())) + (text.length() > 30 ? "..." : ""));
        popupView.setPopupContent(label);
        return popupView;
    }
    return null;
}

What did I wrong? Does the maxTextLength property work on “natural” columns only, not on generated?

As far as I see from the source code, maxTextLength applied only if there are no generators for the column. You could use Formatter for column instead of generator and it should work.

Formatter doesn’t work too, no differences.
The column:

<column id="vaFlats" sortable="false" maxTextLength="30">
    <formatter class="com.company.project.gui.components.formatters.FlatListFormatter"/>
</column>

and formatter class:

public class FlatListFormatter implements Formatter<List<Flat>> {
    @Override
    public String format(List<Flat> flatList) {
        if (flatList != null && flatList.size() > 0) {
            flatList.sort(Comparator.comparing(Flat::getFlOrder));
            StringBuilder stringBuilder = new StringBuilder();
            for (Flat flat : flatList)
                stringBuilder.append(stringBuilder.length() == 0 ? "" : ", ").append(flat.getFlNumber());
            return stringBuilder.toString();
        }
        return null;
    }
}

Call of table.getColumn("vaFlats").setMaxTextLength(30) in init method of the form class didn’t help.
The only solution with PopupView will remain. Thanks.

Try to set (narrow) width for component (label) created in column generator.

That’s the effect:

image

Left cell - generated label with width=200, right - text using formatter.