gwttabsuibinder

Open the default tab in UI


I have the following markup in ui.xml:

<g:HTMLPanel>
    <g:TabPanel ui:field="mainTabPanel">        

        <g:Tab text=""></g:Tab>     
        <g:Tab text=""></g:Tab>
        <g:Tab text=""></g:Tab>

    </g:TabPanel>                       
</g:HTMLPanel>

At the entry point, I initialize the widget and try to specify what tab should be opened by default:

@UiField TabPanel mainTabPanel;
mainTabPanel = new TabPanel();
mainTabPanel.selectTab(1);

But the tab doesn't open.

How to open the default tab in UI?


Solution

  • When calling createAndBindUi, UiBinder creates all widget instances for you and puts them in your fields annotated with @UiField. What happened is that the field is overwritten -> The instance you called selectTab on isn't used anymore.

    Simply remove the line "mainTabPanel = new TabPanel();" and check that "mainTabPanel.selectTab(1);" is called after createAndBindUi.

    If you want to create the TabPanel instance manually, then annotate the field with "@UiField(provided=true)" and ensure that "mainTabPanel = new TabPanel();" before createAndBindUi.