Loading...
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.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

SQLContainer iteration

Hugo Hanisch
10 years ago Mar 20, 2012 4:00pm

Hi:

How do I iterate over a SQLContainer, for example, to add all the data in one column to a string....

regards,

Hugo

Jonatan Kronqvist
10 years ago Mar 21, 2012 8:01am

Hi,

SQLContainer implements the IndexedContainer interface, so you can do something like this:

for (int i = 0; i < container.size(); i++) {
    Object id = container.getIdByIndex(i);
    Item item = container.getItem(id);
    // do stuff with item
}

The only thing to remember is to avoid the getItemIds() method if at all possible, since this method will load all rows from the database, which can be very slow if you have a huge dataset.

Or if you mean to display additional computed cells in a table, you should check out Table.addGeneratedColumn().

HTH,
/Jonatan

Hugo Hanisch
10 years ago Mar 22, 2012 1:03am

Jonatan Kronqvist: Hi,

SQLContainer implements the IndexedContainer interface, so you can do something like this:

for (int i = 0; i < container.size(); i++) {
    Object id = container.getIdByIndex(i);
    Item item = container.getItem(id);
    // do stuff with item
}

The only thing to remember is to avoid the getItemIds() method if at all possible, since this method will load all rows from the database, which can be very slow if you have a huge dataset.

Or if you mean to display additional computed cells in a table, you should check out Table.addGeneratedColumn().

HTH,
/Jonatan

Thank you very much Jonatan, I was actually using getItemIds(), so you help a lot with your answer, which worked perfect...

regards,

Hugo

Hugo Hanisch
10 years ago Apr 05, 2012 2:46pm
Jonatan Kronqvist
9 years ago May 25, 2012 9:59am