Implementing a good Dirty Listener

Hello.

I am trying to implement a dirty listener within a few of my data entry screens. For the sake of argument, lets assume I would like to add a listener to fire before switching Tabs, and before selecting another screen from the menu. My menu is controlled via com.vaadin.ui.MenuBar, and my tab is a standard Vaadin TabSheet.

I have marked things as dirty pretty easily, but my problem is that I haven’t figured how to fire the check Before the screen changes. Currently, when someone tries changing tabs, my check fires but you can see the screen switch to the new tab then back to the dirty tab. As for the menu, I am lost as to what to do.

Please help
Thanks
Dan