tags:

views:

372

answers:

1

I want to add a tab to a certain tab bar from inside the content area. The content area is dynamic, and as such, is located in a different class file. The only way I know of to get the current state of the tab bar (not create a new tab bar object) is to create a static method and variable to access the object. However I'm having problems doing any modification to the tab bar after I get it. I can call functions inside it without much trouble, such as retrieving strings, but I can't add a tab, which is what I need to do. Here's the general gist:

in one class named XYZ:

private static MyPersonalTabPanel mypersonalTabPanel;

public XYZ {
  myperosonalTabPanel = this;
}

in my other file, on the click of a button, I'm triggering this:

MyPersonalTabPanel.getAppInstance().getXYZTabPanel().add(mywidget, "My Widget");

I can use my function "getXYZTabPanel()" with no errors, but when I try to "add" it will simply crash with a white screen, no relevant errors. Any help? I've seen projects add tabs before, but can't find any doing it through a static object like this.

I do not have this inside of an onClick method yet, do I have to do that in order for me to access the static session variable? It's basically being called the moment the page loads.

A: 

Check your initialization order? You need to make sure that the instance of XYZ that you want to add a tab to is the one created by your most recent call to "new XYZ()", and you need to make sure it's already been new'ed up before you try to add the tab.

Also, I assume XYZ extends MyPersonalTabPanel, which extends TabPanel? To clarify, does this code apply to your situation:

public class MyPersonalTabPanel extends TabPanel {
  public static MyPersonalTabPanel instance;

  public MyPersonalTabPanel() {
    instance = this;
  }
}

public class TestClass {
  public void createPanel() {
    RootPanel.get().add(new MyPersonalTabPanel());
  }
  public void addTab(Widget widget) {
    MyPersonalTabPanel.instance.add(widget, "My Widget");
  }
}

Make sure that TestClass's createPanel() gets called before the addTab(Widget) call happens.

Steve Armstrong