A.4. menu.xml
The files of this type are used in the application blocks implementing the generic user interface, such as the Web Client and the Desktop Client. These files define the main menu structure of the application.
XML schema is available at http://schemas.haulmont.com/cuba/6.9/menu.xsd
The file location is specified in the cuba.menuConfig application property. When you create a new project in Studio, it creates the web-menu.xml
file in the root package of the web module, for example modules/web/src/com/company/sample/web-menu.xml
.
The file has the following structure:
menu-config
– the root element.
Elements of menu-config
form a tree structure:
-
menu
– a folding menu containing menu items and other folding menus.menu
attributes:-
id
– identifier of an element, used for name localization (see below). -
description
- a text shown as a tooltip on mouse hover. You can use localized messages from the main message pack. -
icon
- icon of the menu element. See icon for details. -
insertBefore
,insertAfter
– determines whether the item should be inserted before or after a particular element or a menu item with the specified identifier. This attribute is used to insert an element to an appropriate place in the menu defined in files of application components. Before and after elements cannot be used at the same time. -
stylename
- defines a style name for the menu item. See Themes for details.
menu
elements:-
menu
-
item
– menu item (see below). -
separator
– separator.
-
-
item
– menu item.item
attributes:-
id
– unique identifier of an element, used for caption localization (see below). Can be used as screenid
for linking to one of the UI screen elements registered in screens.xml file, if no actions declared. When a user clicks on a menu item, the corresponding screen will be opened in the main application window. -
bean
- the name of bean which can be obtained byAppBeans
(e.g.cuba_Messages
). -
beanMethod
- the name of method from bean (should be used together with thebean
attribute).<item bean="cuba_Messages" beanMethod="getMainMessagePack"/>
-
class
- fully qualified name of class which extendsRunnable
.<item class="com.haulmont.cuba.core.sys.SecurityContextAwareRunnable"/>
-
description
- a text which is shown as a tooltip on mouse hover. You can also use localized messages from the main message pack.<item id="ref$Colour.browse" description="mainMsg://carsColours"/>
-
screen
- non-unique screen identifier (e.g.sec$User.browse
). Can be used as item’sid
if it wasn’t defined.<item screen="sec$User.browse"/>
-
shortcut
– a keyboard shortcut for this menu item. Possible modifiers –ALT
,CTRL
,SHIFT
– are separated with “-”. For example:shortcut="ALT-C" shortcut="ALT-CTRL-C" shortcut="ALT-CTRL-SHIFT-C"
Shortcuts can also be configured in application properties and then used in
menu.xml
file in the following way:shortcut="${sales.menu.customer}"
-
openType
– screen open mode. The following modes are available:WindowManager.OpenType
:NEW_TAB
,THIS_TAB
,DIALOG
,NEW_WINDOW
.Default value –
NEW_TAB
.NEW_WINDOW
mode is only supported in the Desktop Client. For the Web Client it is equivalent toNEW_TAB
mode. -
icon
- icon of the menu element. See icon for details. -
insertBefore
,insertAfter
– determines whether the item should be inserted before or after a particular element or a menu item with the specified identifier. -
resizable
– only relevant toDIALOG
screen open mode. Controls window resizing ability. Possible values −true
,false
.By default, the main menu does not affect the ability to resize dialog windows.
-
stylename
- defines a style name for the menu item. See Themes for details.
item
elements:-
param
– screen parameters passed to the controller’sinit()
method. The properties configured inmenu.xml
override the parameters set in screens.xml with the same name.param
attributes:-
name
– parameter name. -
value
– parameter value. String value, may be converted to an arbitrary object according to the following rules:-
If a string is an entity identifier, specified according to the rules of the
EntityLoadInfo
class, the system loads the specified entity instance. -
If a string has the format
${some_name}
, the value of the parameter will be set to thesome_name
application property. -
Strings
true
andfalse
are converted to the correspondingBoolean
values. -
Otherwise, the string itself becomes the parameter value.
-
-
-
permissions
– an element defining a set of permissions required to make the menu item available to the current user. This mechanism should only be used when item availability should be tied to a specific permission, or to more than one arbitrary permissions. In most cases, the standard capabilities of the security subsystem should be sufficient to manage the menu item availability based on screen identifiers.The element should contain nested
permission
elements, each describing a single required permission. The menu item will only be accessible if all permissions are granted.permission
attributes:-
type
– permission type. The following types are available forPermissionType
:SCREEN
,ENTITY_OP
,ENTITY_ATTR
,SPECIFIC
,UI
. -
target
– an object checked for permission. Depends on permission type:-
SCREEN
– screen identifier, for examplesales$Customer.lookup
. -
ENTITY_OP
– a string formatted as{entity_name}:{op}
, where{op}
–read
,create
,update
,delete
. For example:sales$Customer:create
. -
ENTITY_ATTR
– a string formatted as{entity_name}:{attribute}
, for examplesales$Customer:name
. -
SPECIFIC
– specific permission identifier, for examplesales.runInvoicing
. -
UI
– path to a visual component of a screen.
-
-
-
Example of a menu file:
<menu-config xmlns="http://schemas.haulmont.com/cuba/menu.xsd">
<menu id="sales" insertBefore="administration">
<item id="sales$Customer.lookup"/>
<separator/>
<item id="sales$Order.lookup"/>
</menu>
</menu-config>
menu-config.sales=Sales
menu-config.sales$Customer.lookup=Customers
If the id
is not set, the name of the menu element will be generated from the class name (if the class
attribute is set) or the bean name and the bean method name (if the bean
attribute is set), therefore setting the id
attribute is recommended.