Vaadin 7.6 ContextMenu item click event not fired

Hello,

I have written a simple project to test the new Vaadin 7.6 ContextMenu (v.0.7.3) and it seems that, even if the menu is correctly opened and the items displayed, when any item is clicked the event for that item never gets fired. Oposed to the code sample in the documentation (https://vaadin.com/blog/-/blogs/using-contextmenu-with-vaadin-7-6) I am using Java 7, instead of 8 so I have changed the lambda expressions in the item definitions into the “new Menu.Command(){@Override public void menuSelected(MenuItem menuItem) {…}}” equivalent. The entire code is this:

VerticalLayout buttonContainer= new VerticalLayout();
buttonContainer.setSizeFull();
Button testButton= new Button(“Push”);

ContextMenu testMenu= new ContextMenu(this, false);

testMenu.setAsContextMenuOf(testButton);

final MenuItem item1= testMenu.addItem(“Element 1”, new Menu.Command() {
@Override
public void menuSelected(MenuItem menuItem) {
Notification.show(“Element 1”);
}
});
buttonContainer.addComponent(testButton);

Is there any limitation when using the ContextMenu in Java 7?

Thanks in advance!

Hi,

Sounds weird. I’m pretty sure Java 7 has nothing to do with this. I’d suggest to try addin
a github issue
with details about your Vaadin version, browser and OS as well.

cheers,
matti

Hi,

I’m having the same problem. Even the code is the same.

ContextMenu opens, shows the items, but nothing happens when I click on them.
If I try to add a ContextMenuOpenListener, onContextMenuOpen is called correctly.

I’ve tried both with Java 7 (new Menu.Command(){…}) and Java 8 (lambda) with no success.
Vaadin 7.6.5 and ContextMenu 0.7.3. Tested on Windows and Mac with Chrome.
I’ll do a couple more tests then I’ll try to add an issue to the github page… even if this problem seems a bit odd :\

Marco

Hi,

as Matti proposed I tried to add a new issue at github but I realised someone was asking something related to Java 7 (
https://github.com/vaadin/context-menu/issues/1
) but it was closed. I have tried to compile the source code for Java 7 and even if it is compiled ok it do not work at all. As Marco says, the context menu is correctly created and the onContextMenuOpen event is fired well but the menu item onclick events never get called. I have tried with the most updated Vaadin version and the problem remains. As I read, there was any change related to how events are processed in Vaadin 7.6. I wonder if it can be related to this (any incompatible library conflicting,…).

Regards
Ruben

Hi,

The test code shared by Ruben works perfectly for me (Mac, Chrome, Safari, FF). Somebody should now present a reduced example application (preferrably a Maven built) where this can be reproduced. Otherwise there isn’t that much we can do.

cheers,
matti

Hi,

Matti, in order to set a common test framework, could you tell me which Vaadin maven dependencies have you used to test my code?.

Regards.
Ruben

No need to create any special test framework. Just create a project with vaadin-archetype-application, add the dependency and create the setup where the issue can be reproduced manually.

cheers,
matti

Hi,

I’m not familiar with maven, however I think I’ve found the problem (at least for my case).
I use a custom theme based on the old reindeer theme. If I switch to the new valo theme (with the annotation @Theme(“valo”)) the problem disappears and clicks on menu items works fine.
With the default reindeer (@Theme(“reindeer”)) the problem persists.

Maybe I’ll switch to valo for this project.

Hi,

I confirm what Marco says. I’ve created a maven project using the archetype (as Matti proposed). After including the addon and modify the UI to perform the test, it works by default. I’ve checked against my source project and dependencies seem not to be the problem. Changing the theme to any other not Valo one makes the contextmenu to fail when items are selected. I’ve tried to include the missing css elements for contextmenu in a reindeer derived theme but it already fails so I supose some other elements from Valo theme are necessary. I’ve also attached the test project I’ve used.

Thank you Matti and Marco!
Ruben

25607.zip (25 KB)

Yep, just verified this myself, for some reason with “reindeer” theme it fails. I created
an issue about this
to github. Thanks for everyone who helped to reduce this nasty issue!

cheers,
matti

It seems like the problem is related to
this issue
; the command is invoked only if widget is attached.
It works for example if you add in your theme an animation when menubar popup must disappear

@import "../reindeer/reindeer.scss";

@mixin mytheme {
  @include reindeer;

  // Insert your own theme rules here

  .v-menubar-popup[class*="animate-out"]
 {
    -webkit-animation:  v-notification-animate-out 120ms;
    -moz-animation:  v-notification-animate-out 120ms;
    animation:  v-notification-animate-out 120ms;
  }

}

That workaround works perfectly for me. You saved me a lot of time.

Thank you very much to everyone!