Menu Configuration
To generate a custom menu, the MenuConfiguration may be used for collecting defined server and client routes. Client routes are taken from the FileSystem routes definition. Server routes come from routes annotated with @Menu.
The collected menu items are filtered by access control from the UI (i.e., NavigationAccessControl and ViewAccessChecker). If the application has login and route defined Roles, the returned list is filtered on only available routes.
Creating Routes Menu
For a Flow application, any route annotated with @Menu is eligible for collection.
To get the available menu routes, call the static method MenuConfiguration.getMenuEntries(). This returns a List<MenuEntry>, first sorted in order found, then by path alphabetically and locale. It makes creating a simple menu by using Anchor, which can look like this:
Source code
Java
List<MenuEntry> menuEntries = MenuConfiguration.getMenuEntries();
menuEntries.forEach(entry -> layout.add(new Anchor(entry.path(), entry.title())));To get the same entries nested into a hierarchy instead of a flat list, call MenuConfiguration.getMenuEntriesTree(). It returns only the root entries; each entry’s descendants are reached through MenuEntry.children():
Source code
Java
for (MenuEntry entry : MenuConfiguration.getMenuEntriesTree()) {
sideNav.addItem(toItem(entry)); // recurse into entry.children()
}A server view is nested under the menu entry named by its @Menu parent, if one is declared, or otherwise under its logical route parent. A parent that is not itself part of the menu is skipped in favor of its nearest included ancestor, and a view with no included ancestor becomes a root entry. Client views have no server-side route hierarchy and are always root entries without children.
Data Returned for Menu Entries
The MenuEntry for a route contains information on the route. Using this data, it’s possible to populate a menu, automatically.
The data contained is as follows:
path-
Route path that should be used for navigation.
title-
Title set in the
@Menuannotation or the@PageTitle, if defined — otherwise, the class simple name. For the client, title is populated from the FS router data. order-
Order number for the menu entry, if defined.
icon-
Icon to use in the menu. This value can be entered inside a
<vaadin-icon>element’siconattribute. It accepts icon group and a name likevaadin:file. Or the value can be given in<vaadin-icon>element’ssrcattribute, which takes the path to the icon (e.g.,line-awesome/svg/lock-open-solid.svg). menuClass-
Source class of the
@Menuannotation. Always null for client routes. children-
Entries nested under this one, returned by
getMenuEntriesTree(). Nevernull, but always empty for the flat list returned bygetMenuEntries().
647922A8-D542-4FA7-AAF6-44D40FC6A33B