How to refresh Table based on QueryContainer

Hello,

I’m writing a blog on using Vaadin to very quickly construct a front end for testing/debugging Java EE 5 and 6 technologies. I’m stuck on one last part and haven’t found an answer yet in the forums. My application consists of a tab that allows normal CRUD-type operations on some JPA entities. Then in another tab I have Vaadin UI Tables tied directly to the database tables so that a developer can see the results of calling the back end directly from the web application.

Here is a simplified version of my code (exception handling removed):

class SQLPanel extends Panel {
    // fields omitted such as JDBC URL, username, password, and query
    // the query is of the form "select * from MY_TABLE"

    SQLPanel() {
        Connection connection = DriverManager.getConnection(URL, USER, PW);
        QueryContainer qc = new QueryContainer(query, connection);
        Table table = new Table(String.format("\"%s\"", query), qc);
        containers.add(qc);
        addComponent(table);

        Button refreshButton = new Button("Reload Tables",
            new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    // what goes here?
                }
            });
        addComponent(refreshButton);
    }
}

My question is about what to call in the buttonClick() method to refresh the table from the database. I’ve tried calling ‘qc.refresh();’ there but that didn’t do it, and I’ve tried figuring out how to fire the right events to cause the table to reload. Can you let me know what I should add here?

I’m using Vaadin version 6.1.5 but can easily switch to any version in the Maven repository.

Thank you,
Bobby

After checking all the examples I can find, it looks like the way to do this is to create a new QueryContainer and set it with Table#setContainerDataSource(). Does that sound correct?

QueryContainer does have a refresh() method that reloads data from the query, but then I’d need to keep a handle to that object and the table, and then (I assume) request a repaint for the table. It looks faster just to create a new one and set it.

I haven’t given this more than a passing thought, but it might be nice to have the refresh() method also repaint the table – maybe a boolean that could be passed in to synchronize the table to the data or not.

Cheers,
Bobby