Build a home button - return to mainscreen

Hi,
in jmix 1.5.5.
I’d like to have the first button in the sidemenu to work as a home button. Clicking home should close all tabs and return to mainscreen.

Thanks for ideas in advance,
br
HP

Hello @Eichers ,

You can add a button to MainScreen:

main-screen.xml

  ...
  <button id="mainBtn" caption="msg://mainCaption"/>
  <sideMenu id="sideMenu"
            width="100%"
            stylename="jmix-drawer-content"/>
  ...

MainScreen.class

  @Subscribe("mainBtn")
  public void onMainBtnClick(final Button.ClickEvent event) {
      screenBuilders.screen(this)
              .withOpenMode(OpenMode.ROOT)
              .withScreenClass(MainScreen.class)
              .show();
  }

Or you can add a new menu item to the side menu that calls a method from the bean:

MainService.class

@Component("bs_MainService")
public class MainService {

    public void openMainScreen() {
        AppUI.getCurrent().getScreens().create(MainScreen.class, OpenMode.ROOT)
                .show();
    }
}

Regards,
Nikita

2 Likes