|
| 1 | +--- |
| 2 | +title: Menu Configuration |
| 3 | +description: Collecting menu annotated routes for menu generation. |
| 4 | +order: 115 |
| 5 | +--- |
| 6 | + |
| 7 | + |
| 8 | += Menu Configuration |
| 9 | + |
| 10 | +To generate a custom menu, the [classname]`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 [annotationname]`@Menu`. |
| 11 | + |
| 12 | +The collected menu items are filtered by access control from the [classname]`UI` (i.e., [classname]`NavigationAccessControl` and [classname]`ViewAccessChecker`). If the application has login and route defined `Roles`, the returned list is filtered on only available routes. |
| 13 | + |
| 14 | + |
| 15 | +== Creating Routes Menu |
| 16 | + |
| 17 | +For a Flow application, any route annotated with [annotationname]`@Menu` is eligible for collection. |
| 18 | + |
| 19 | +To get the available menu routes, call the static method `MenuConfiguration.getMenuEntries()`. This returns a [classname]`List<MenuEntry>`, first sorted in order found, then by path alphabetically and locale. It makes creating a simple menu by using [classname]`Anchor`, which can look like this: |
| 20 | + |
| 21 | +[source,java] |
| 22 | +---- |
| 23 | +List<MenuEntry> menuEntries = MenuConfiguration.getMenuEntries(); |
| 24 | +menuEntries.forEach(entry -> layout.add(new Anchor(entry.path(), entry.title()))); |
| 25 | +---- |
| 26 | + |
| 27 | + |
| 28 | +== Data Returned for Menu Entries |
| 29 | + |
| 30 | +The [classname]`MenuEntry` for a route contains information on the route. Using this data, it's possible to populate a menu, automatically. |
| 31 | + |
| 32 | +The data contained is as follows: |
| 33 | + |
| 34 | +`path`:: |
| 35 | +Route path that should be used for navigation. |
| 36 | + |
| 37 | +`title`:: |
| 38 | +Title set in the [annotationname]`@Menu` annotation or the [annotationname]`@PageTitle`, if defined -- otherwise, the class simple name. For the client, title is populated from the FS router data. |
| 39 | + |
| 40 | +`order`:: |
| 41 | +Order number for the menu entry, if defined. |
| 42 | + |
| 43 | +`icon`:: |
| 44 | +Icon to use in the menu. This value can be entered inside a `<vaadin-icon>` element's `icon` attribute. It accepts icon group and a name like `vaadin:file`. Or the value can be given in `<vaadin-icon>` element's `src` attribute, which takes the path to the icon (e.g., `line-awesome/svg/lock-open-solid.svg`). |
| 45 | + |
| 46 | +`menuClass`:: |
| 47 | +Source class of the [annotationname]`@Menu` annotation. Always null for client routes. |
| 48 | + |
| 49 | +[discussion-id]`647922A8-D542-4FA7-AAF6-44D40FC6A33B` |
0 commit comments