javacuba-platform

How can I open a specific Tab of a Tabsheet with an Button in CUBA Platform?


I created a Dashboard with a menubutton fragment. When I click on a button a new Screen is opening. And now I want to open a specific tab of this screen. In default always the first tab of a screen opens up, but I need to specify. My code looks like this:

public void onBaldUeberfaelligBtnClick() {
  screenBuilders.screen(this)
            .withScreenClass(AufgabenuebersichtBrowse.class)
            .build()
            .show();
}

Solution

  • You can introduce a method in your AufgabenuebersichtBrowse class that switches to the needed tab. And then invoke this method after creating the screen, something like this:

    public class AufgabenuebersichtBrowse extends ... {
    
        @Inject
        private TabSheet tabSheet;
    
        public void switchToMyTab() {
            tabSheet.setSelectedTab("tab2");
        }
    
    
    public void onBaldUeberfaelligBtnClick() {
        AufgabenuebersichtBrowse screen = screenBuilders.screen(this)
                .withScreenClass(AufgabenuebersichtBrowse.class)
                .build();
        screen.switchToMyTab();
        screen.show();
    }
    

    See also the docs on opening screens: https://doc.cuba-platform.com/manual-7.2/opening_screens.html#screen_parameters