In jmix 1.5 we used the sidemenu to explore the fields of classes and nested objects to find paths for a beanwrapper. After the update to jmix 2 we cannot find a solution how to do this.
Hello Eduardo!
In Jmix 2.x you can use JmixListMenu
component as a replacement for SideMenu
. In XML it has <listMenu>
tag, for instance:
.main-view.xml
<nav id="navigation" ...>
<listMenu id="menu"/>
</nav>
Do you mean classes and beans as menu items? In 2.x JmixListMenu
applies only bean menu items. You can add them like this:
.menu.xml
<menu id="application" ...>
...
<item bean="myMenuBean"
beanMethod="navigateToUsersList"
title="Menu bean"/>
</menu>
And bean itself:
@Component
public class MyMenuBean {
private final ViewNavigators viewNavigators;
public MyMenuBean(ViewNavigators viewNavigators) {
this.viewNavigators = viewNavigators;
}
public void navigateToUsersList() {
viewNavigators.listView(User.class)
.navigate();
}
}
To get the menu item instance you can do the following:
@ViewComponent
private JmixListMenu menu;
@Subscribe
public void onInit(final InitEvent event) {
JmixListMenu.BeanMenuItem beanMenuItem =
(JmixListMenu.BeanMenuItem) menu.getMenuItem("myMenuBean#navigateToUsersList");
// override click on item
beanMenuItem.withClickHandler(menuItem -> {
log.info("Bean menu item clicked");
});
}