the MainLayout
is @Slf4j public class MainLayout extends AppLayout implements BrowserWindowResizeListener, AfterNavigationListener {
You have to implement AfterNavigationObserver.
AfterNavigationListener is a global listener that should be registered to the UI
this one worked but the main problem still persists
this is not iterating the child items recursively
.filter(sideNavItem -> null != sideNavItem.getPath())
.filter(sideNavItem -> sideNavItem.getParent().isPresent())
.filter(sideNavItem -> {
log.warn("current path is {}", sideNavItem.getPath());
return afterNavigationEvent.getLocation().getPath().equals(sideNavItem.getPath());
}
)
.findFirst()
.ifPresentOrElse(sideNavItem -> {
log.warn("current path is {}", sideNavItem.getPath());
}, () -> {
log.warn("current path not matching with sideNavItem is {}", afterNavigationEvent.getLocation().getPath());
});```
and this is how the parent and child are created
expenses.addItem(new SideNavItem("NewExpense", ExpensesForm.class));```
You can recurse on SideNavItem.getItems() and when you find the active item, call getParent to expand all parent SideNavItem
I’ll let Vaadin does this instead since this is a required feature
Here is the one I could make ```public SideNavItem findSideNavItem(List sideNavItems, String path) {
for (SideNavItem sideNavItem : sideNavItems) {
if (null != sideNavItem.getPath() && sideNavItem.getPath().equals(path)) {
return sideNavItem;
}
if (sideNavItem.getChildren().count() > 0) {
SideNavItem matchedChild = findSideNavItem(sideNavItem.getItems(), path);
if (matchedChild != null) {
SideNavItem item = (SideNavItem) matchedChild.getParent().get();
item.setExpanded(true);
return matchedChild;
}
}
}
return null;
}```
if someone has a better solution, please reply here