Can You add a submenu to a context menu in Vaadin 10 ?

Hi.

I am struggling a little with this problem. It was very easy and obvious in Vaadin 8 with the MenuItem.addItem() method. But this seems to be missing in Vaadin 10.

Or do I miss something ?

Bye, Torsten…

Yes, this is currently a missing feature in the new versions: https://github.com/vaadin/vaadin-context-menu/issues/124

Hey Torsten!

If I understood right, you tried to use this component under vaadin flow:
https://vaadin.com/directory/component/vaadin-contextmenu

The problem is that while this is a supported under v7 and v8, v10 (flow) is not quite backwards compatible with components like this. There has been a massive version change between v8 and v10 (not like v7-v8), and ContextMenu does not comply with the flow class hierarchy. For instance, if you look at the source code, you’ll see that in its constructor it expects an AbstractComponent as a parent component, while this works elsehow in flow:
https://github.com/vaadin/context-menu/blob/83b5d0963d97e6c8800aaf13fc9b6e629f424f3e/vaadin-context-menu-addon/src/main/java/com/vaadin/contextmenu/ContextMenu.java#L84

What you can do however is to use external WebComponents and integrate it into your projects. For instance, there exists a vaadin component called vaadin-context-menu which is not to be confused with the one you were trying to use.
https://github.com/vaadin/vaadin-context-menu

WebJars dependency:

<dependency>
    <groupId>org.webjars.bowergithub.vaadin</groupId>
    <artifactId>vaadin-context-menu</artifactId>
    <version>4.1.0</version>
</dependency>

You might have to create your own java API for this webcomponent I think.
See also this and the following articles:
https://vaadin.com/docs/v11/flow/web-components/integrating-a-web-component.html

Hi.

I don’t believe I am using that version. Its embarrassing but I was being imprecise about the component. It is in fact a GridContextMenu.

GridContextMenu contextMenu = vaadinGrid.addContextMenu();

originating from this source

		<dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-grid-flow</artifactId>
            <version>1.2.0</version>
        </dependency>

Can’t tell how it is connected with the 7 and 8 Version.

Looking up on mvnrepository this artifact seems to be really new. (Sep 12, 2018)
Even on Vaadin 11 Java API browser I don’t yet see this new GridContextMenu.
https://vaadin.com/api/platform/11.0.1/com/vaadin/flow/component/grid/package-summary.html

Other classes seem to be there. My guess is that they have not published official documentation on this feature. It might be missing as pointed out by Juoni above. But there might be a solution in this 1.2.0 vaadin-grid-flow version.

This vaadin-grid-flow artifact seems to be some advanced version of the Grid Componment, which is (according to my guesses) independent from the vaadin-context-menu which I mentioned in my previous reply. You can try to search trough the available methods provided by vaadin-grid-flow 1.2.0, and in the meantime wait for documentation or new features to be added to vaadin-context-menu which is expected to be able to be added to pretty much any components.