TabSheet ClickListener

I have the following code which chokes when I add the listener. I have tried moving it before adding tabs. I tried implementing TabSheet.SelectedTabChangeListener. It fails every time, and I am clueless as to what is going wrong.

Thanks for your help in advance.

public MainLayout() {
	setCompositionRoot(tabSheet);
	
	this.setHeight("100%");
	this.setWidth("100%");

	this.primaryContent = new PrimaryContentPanel();

	main = new MainTab(this.primaryContent);
	
	this.tabSheet.addTab(main, "Home", null);
	this.tabSheet.addTab(ContentMan, "Content Management", null);
	this.tabSheet.addTab(AssetMan, "Asset Management", null);
	
	this.tabSheet.addListener(new TabSheet.SelectedTabChangeListener() {
	    public void selectedTabChange(SelectedTabChangeEvent event) {
		getApplication().getMainWindow().showNotification("Caught Event");
	    }
	});
}

I assume that the getApplication().getMainWindow() throws a NullPointerException. You should try tabsheet.getApplication().getMainWindow()

Adding the listener should work that way, I don’t see any problem with that. Are you sure that it fails on that method and not before? What are the ContentMan and AssetMan? Are they members or something else? Are you sure you initialize them?

How exactly does it fail?

The “getApplication().getMainWindow()” is a bit extra and a bit dangerous, because if you ever enable multi-window behaviour in your application, it will fail because it won’t refer to the containing window of the CustomComponent, but always the main window. Calling “getWindow()” should be enough.

It won’t throw a NullPointerException, as suggested by Sascha, as it’s only called when the user selects another tab. Well, if you change the selection from code before the component is attached to a window, it will throw an NPE, but you don’t do that in that constructor at least.

PS. Why do you use “this.” for references to members?

Very much Thanks. it’s work for me.