Selected menu item doesn't match open tab

Hello,

When we select some item in the left side menu, select other item and return to the first open tab, selected menu item doesn’t correspond to open tab.

For example, if we click “Pets” menu item, “Pets” menu item will be selected and “Pets” tab will be open. Then if we click “Owners” item, “Owners” menu item will be selected and “Owners” tab will be open. Then if we switch to “Pets” tab, it will be open but “Owners” item still will be selected.

Main tabsheet doesn’t seem to be available from ExtMainScreen.

Could you please clarify how we can update selected item in the side menu when we switch between tabs?

Thanks.

Hi,

As selectOnClick attribute name says, it isn’t intended to change selection on tab change, it changes selection on item click. Nevertheless, such a feature can be implemented from scratch. To do so:

  1. Extend the main screen and add the selectMenuItem method:
@UiController("extMainScreen")
@UiDescriptor("ext-main-screen.xml")
public class ExtMainScreen extends MainScreen {

    public void selectMenuItem(String id) {
        SideMenu sideMenu = getSideMenu();
        if (sideMenu != null) {
            MenuItem menuItem = sideMenu.getMenuItem(id);
            if (menuItem != null) {
                sideMenu.setSelectedItem(menuItem);
            }
        }
    }
}
  1. Then add WorkAreaTabChangedEvent listener as follows:
@Component
public class WorkAreaTabChangeListener {

    @EventListener
    public void onTabChanged(WorkAreaTabChangedEvent e) {
        Screen activeScreen = getActiveScreen();
        if (activeScreen != null) {
            ExtMainScreen mainScreen = (ExtMainScreen) getOpenedScreens().getRootScreen();
            mainScreen.selectMenuItem(activeScreen.getId());
        }
    }

    @Nullable
    public Screen getActiveScreen() {
        OpenedScreens openedScreens = getOpenedScreens();

        Iterator<Screen> dialogsIterator = openedScreens.getDialogScreens().iterator();
        if (dialogsIterator.hasNext()) {
            return dialogsIterator.next();
        }

        Iterator<Screen> screensIterator = openedScreens.getCurrentBreadcrumbs().iterator();
        if (screensIterator.hasNext()) {
            return screensIterator.next();
        }

        return null;
    }

    private OpenedScreens getOpenedScreens() {
        return AppUI.getCurrent().getScreens().getOpenedScreens();
    }
}

Gleb

2 Likes

Hello,

It works. Thank you.