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?