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.
How to set a message inside a Table when no records found?
Hi there,
I'm trying to set a message inside a Table when no records found into database.
How can I do this properly? I found a way there but that does not match my needs. I have to manage a multi-language website so I have to display the message in different languages.
Any thoughts would be appreciated. Thank you !
Lrt
I've never used it, but I think you can do this using a Table.RowGenerator.
You can replace the table, with label dynamicaly:
if (!recordsFound()) {
Label noChanges = new Label(__("NO_RECORDS"), ContentMode.HTML);
noChanges.setSizeUndefined();
noChanges.addStyleName(ValoTheme.LABEL_H1);
noChanges.addStyleName(ValoTheme.LABEL_COLORED);
getViewer().replaceComponent(content, noChanges);
((AbstractOrderedLayout) getViewer()).setComponentAlignment(noChanges, Alignment.MIDDLE_CENTER);
}
Auke te Winkel: I've never used it, but I think you can do this using a Table.RowGenerator.
Hi Auke,
Thank you for answering me back.
I tried something like that :
if (myTable.isEmpty()) {
myTable.setRowGenerator(new Table.RowGenerator() {
@Override
public Table.GeneratedRow generateRow(Table table, Object itemId) {
Table.GeneratedRow row = new Table.GeneratedRow();
row.setText("No records found");
return row;
}
});
}
... but I got nothing displayed at all into my table. What am I doing wrong here?
I did not find any conclusive examples on the web in matter to achieve it.
Do you have an example or other suggestions to make it work?
Thank you,
Lrt
Agata Vackova: You can replace the table, with label dynamicaly:
if (!recordsFound()) { Label noChanges = new Label(__("NO_RECORDS"), ContentMode.HTML); noChanges.setSizeUndefined(); noChanges.addStyleName(ValoTheme.LABEL_H1); noChanges.addStyleName(ValoTheme.LABEL_COLORED); getViewer().replaceComponent(content, noChanges); ((AbstractOrderedLayout) getViewer()).setComponentAlignment(noChanges, Alignment.MIDDLE_CENTER); }
Hi Agata,
Thank you for answering me back.
I already thought about it and it could be a good alternative but that is not what I want as result.
I want the "No records found" message displaying into the table.
Any other suggestions?
Thank you,
Lrt
Lrt Hrl:
Auke te Winkel: I've never used it, but I think you can do this using a Table.RowGenerator.
Hi Auke,
Thank you for answering me back.
I tried something like that :
if (myTable.isEmpty()) { myTable.setRowGenerator(new Table.RowGenerator() { @Override public Table.GeneratedRow generateRow(Table table, Object itemId) { Table.GeneratedRow row = new Table.GeneratedRow(); row.setText("No records found"); return row; } }); }
... but I got nothing displayed at all into my table. What am I doing wrong here?
I did not find any conclusive examples on the web in matter to achieve it.Do you have an example or other suggestions to make it work?
Thank you,
Lrt
You probably need to add an item to display the message:
if (myTable.isEmpty()) {
myTable.addItem();
myTable.setRowGenerator(new Table.RowGenerator() {
@Override
public Table.GeneratedRow generateRow(Table table, Object itemId) {
Table.GeneratedRow row = new Table.GeneratedRow();
row.setText("No records found");
return row;
}
});
}