One of the Tabs has a huge table with more than 50,000 rows. So I was wondering if I can load the tab only when it is selected.
I failed miserably using the code below.
Any component that you add to the layout will be processed immediately, but sent to the client only when visible. What you want here, I presume, is to build your table content when the user selects the tab.
The most easy solution would be to add the table to the Tab, but not adding any items. Just keep a reference to the table in your class somewhere. Then you can use the listener to call a fillTable() method that actually fetches the data, adds the items to the table and initializes any other settings in it.
To optimize the above a bit, you should actually create a new container, fill it, and add it to the table; this gets rid of a LOT of internal Table events that you don’t need when filling the table for the first time. Like this:
private void fillTable(){
Container c= new IndexedContainer();
// init container properties
// fetch data
// fill the container
table.setContainerDataSource(c);
}
This will delay filling of the Table to the last possible moment.
Somewhat irrelevant but I noticed that you call requestRepaint. You should never have to call that method by hand. It shouldn’t affect anything, and if it does, then you have probably found a bug.