Duplicate components in liferay

Hi,

I have only recently started working with Vaadin and Liferay so please excuse my ignorance. I am currently working on a custom Liferay portlet that reads from a MySQL database, writes the results to a table, and adds that table to the visible portlet. I am doing this using code which looks similar to this.

Window window = new Window(“Vaadin SQL Project”);
SetMainWindow(window);

Table table = new Table(“Data”);
populateTableWithSQL(table);

// on button click I am doing a:
window.addComponent(table)

// I have another button that attempts a:
window.removeComponent(table);

My problem is that the removeComponent(table) piece does not remove the table from the portlet and on additional clicks the addComponent(table) simply places more tables under the existing one. I think i am just not referencing the “table” correctly for it to know what to remove but i am not sure how i should be. I have also tried replaceComponent(table) and that also does not seem to do anything.

Any help would be GREATLY appreciated! I have to have this done by the end of the month and i’m kind of freaking out about it.

Thanks in advance!

Here’s a minimal example that should work

    @Override
    public void init() {
        final Window mainWindow = new Window("Window Application");
        table = myStaticCreateTableMethod();
        Button replace = new Button("replace");
        replace.addListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                Table newTable = myStaticCreateTableMethod();
                mainWindow.replaceComponent(table, newTable);
                table = newTable;
            }
        });
        
        mainWindow.addComponent(table);
        mainWindow.addComponent(replace);
        setMainWindow(mainWindow);
    }

Got it working it seems i was calling Table table = New Table() one too many times and it didn’t know which to remove. Thank you for the speedy response!