Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
addGeneratedColumn on FilterTable = no filter
Is anyone able to use addGeneratedColumn with FilterTable? When I add a generated column and return something as simple as a blank string, my entire component fails to load. No errors on the console, just doesnt load anything.
My FilterTable goes from working fine to nothing happening at all with just the following code:
filterTable.addGeneratedColumn("myprop", new ColumnGenerator() {
public Object generateCell(CustomTable customTable, Object itemId, Object columnId) {
return "string";
}
});
FWIW - addGeneratedColumn *does* work if its overriding a real container property, but it does not work for a truly generated column. It should be able to do that, correct?
Hi,
the filters used in FilterTable rely on the Container.Filterable interface. Therefore it is not possible to create filters for generated properties which are not present in the container. Nevertheless - it should not fail in the way you describe. Correct behavior would be to just not display a filter for such generated properties. I'll take a look at the bug when I have the time.
-Tepi
What about columns with foregin key that only are using generatedColumn to chage foregin ID to some readable property e.g. COMPANY, so that column only cover real column in Container (exacly like in this tutorial https://vaadin.com/tutorial/sql/-/section/update-ui.html#N2022E). I want to create ComboBox to chose company and filter that generatedcolumn. I tried to do this but for now without success - application works, combobox is rendered properly but changing selecteditem is not filtering table:
KontrahTable.addGeneratedColumn("ID_FIRMA", new ColumnGenerator() {
@Override
public Object generateCell(CustomTable source, Object itemId,
Object columnId) {
if (source.getItem(itemId).getItemProperty("ID_FIRMA").getValue() != null) {
Label l = new Label();
int firmaId = (Integer)source.getItem(itemId).getItemProperty("ID_FIRMA").getValue();
l.setValue(AppData.getDataSource().getFirmaNazwa(firmaId));
l.setSizeUndefined();
return l;
}
return null;
}
});
public class KontrahFilterGenerator implements FilterGenerator {
@Override
public Filter generateFilter(Object propertyId, Object value) {
if ("ID".equals(propertyId) || "WIEK".equals(propertyId)) {
/* Create an 'equals' filter for the ID field */
if (value != null && value instanceof String) {
try {
return new Compare.Equal(propertyId,
Integer.parseInt((String) value));
} catch (NumberFormatException ignored) {
// If no integer was entered, just generate default filter
}
}
}
if ("ID_FIRMA".equals(propertyId)) {
if (value != null) {
return new Compare.Equal(propertyId, Integer.parseInt((String) value));
}
}
return null;
}
@Override
public AbstractField getCustomFilterComponent(Object propertyId) {
if ("ID_FIRMA".equals(propertyId)) {
ComboBox cbFirmy = new ComboBox();
cbFirmy.setContainerDataSource(AppData.getDataSource().getFirmyContainer());
cbFirmy.setItemCaptionPropertyId("NAZWA");
cbFirmy.setItemCaptionMode(AbstractSelect.ITEM_CAPTION_MODE_PROPERTY);
cbFirmy.setImmediate(true);
return cbFirmy;
}
return null;
}
...
I FOUND SOLUTION
I just casted value wrong. In KontrahFilterGenerator I changed this line:
return new Compare.Equal(propertyId, Integer.parseInt((String) value));
to:
return new Compare.Equal(propertyId, Integer.parseInt(value.toString()));
and works like a charm :)
Teppo Kurki: Hi,
the filters used in FilterTable rely on the Container.Filterable interface. Therefore it is not possible to create filters for generated properties which are not present in the container. Nevertheless - it should not fail in the way you describe. Correct behavior would be to just not display a filter for such generated properties. I'll take a look at the bug when I have the time.
-Tepi
Hi Teppo,
One important question for our project is that with your last filterTable version is possible filter columns added with addNestedContainerProperty??, because with the version 0.7.1 we can not and the table show a grey panel in this case.
Teppo Kurki:
Hi,the filters used in FilterTable rely on the Container.Filterable interface. Therefore it is not possible to create filters for generated properties which are not present in the container. Nevertheless - it should not fail in the way you describe. Correct behavior would be to just not display a filter for such generated properties. I'll take a look at the bug when I have the time.
-Tepi
Would there be any kind of workadoung to make Generated Columns filterable? I get the behaviour as you describe it (no error, and no filter)