Closable TabSheet callback to prevent closing?

I have a tabsheet on which I’d like to use the close gadgets, and when the user clicks on the close gadget, ask the user, “Are you sure you want to close?” It appears that the only callback that occurs is the onTabClose() method on TabSheet.CloseHandler, and this occurs after the close has already happened. Is there no way to cancel the close event based on a user’s response? The way I’m doing this currently is I have a button with an X on it on the tab itself, but I’m not satisfied with that, because it does not look good.

Thanks in advance,

Perhaps you could work around the problem by reopening the tab after it is closed. It might cause some annoying flicker though, as
in this workaround

Thanks, Marko. It looks like it might be possible to add this capability to Vaadin, based on my quick research into GWT. The onTabClose() method would have to be changed to add an event object argument, and the event would need to allow you to call cancel() or set doit=false to prevent the tab from closing. I guess I need to add this feature request via Trac. There are other places in Vaadin that would benefit from the same ability to cancel events (switching tabs is another such example).

Hi, I added ticket
that includes also a similar ealier request for an event to prevent tab changes. You could add yourself as Cc for the ticket or otherwise follow it.

The request for tab change event was
in this forum post

You can provide the tabsheet with your own closehandler for just this purpose. Then you can choose not to remove tab if you don’t want to, or present the user with a dialog and act depending on the answer from that dialog.

Doesn’t CloseHandler.onTabClose() get called after the tab has already been closed? If so, how would I prevent removing the tab, if it has already been removed?

No. It is the CloseHandler that should perform the removing, it is not done if you specify a custom handler of your own and do not remove the tab there yourself.

See the source code for clarification. As you see, the default handler calls removeComponent on the TabSheet (from

    public TabSheet() {
        // expand horizontally by default
        setWidth(100, UNITS_PERCENTAGE);
        setCloseHandler(new CloseHandler() {
            public void onTabClose(TabSheet tabsheet, Component c) {

Thank you, Jouni! I don’t know how I missed this before.