Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
ContextMenu not appearing. What am I missing?
I have a Grid in a VerticalLayout, and a ContextMenu attached to it.
However, when right clicking a row, the ContextMenuOpenEvent fires, but I never see the menu itself.
In short - I see the itemId log. But I never see the "Compare" item in a menu, and cannot get the "Ha!" notification.
What am I missing?
Here is the code:
//Add context menu
GridContextMenu contextMenu = new GridContextMenu(grid);
// Menu
contextMenu.addGridBodyContextMenuListener(new GridContextMenu.GridContextMenuOpenListener() {
@Override
public void onContextMenuOpen(GridContextMenuOpenEvent e) {
contextMenu.removeItems();
final Object itemId = e.getItemId();
log.info(itemId.toString());
contextMenu.addItem("Compare", new Menu.Command() {
@Override
public void menuSelected(MenuItem menuItem) {
Notification.show("Ha!");
}
});
}
});
Yeah, I had the same problem. Cannot remember what fixed it, though. :-(
However I can see my code within the onContextMenuOpen() method is slightly different in that I get the ContextMenu to act on from the event.
//Add context menu
GridContextMenu contextMenu = new GridContextMenu(grid);
// Menu
contextMenu.addGridBodyContextMenuListener(new GridContextMenu.GridContextMenuOpenListener() {
@Override
public void onContextMenuOpen(GridContextMenuOpenEvent e) {
ContextMenu cMenu = event.getContextMenu();
cMenu.removeItems();
final Object itemId = e.getItemId();
log.info(itemId.toString());
cMenu.addItem("Compare", new Menu.Command() {
@Override
public void menuSelected(MenuItem menuItem) {
Notification.show("Ha!");
}
});
}
});
BUT. I don't think that's why.
Does your log statement fire ?
Have you checked that you've recompiled the widgetset after adding add-on to your project? Try checking in web browser's F12 tool if there are any errors.
I am getting the the itemId log printing as expected, and I don't see any errors in the browser console.
I didn't specifically recompile the widgetset. Is it necessary?
I do see in the maven log these lines:
[INFO] --- vaadin-maven-plugin:7.6.3:update-widgetset (default) @ winehouse-server ---
[WARNING] GWT plugin is configured to detect modules, but none were found.
[INFO] No widgetsets to update.
[INFO] To create a widgetset, define a non-existing module in your pom.xml .
I don't have a custom widgetset, I don't remember exactly, but I believe I removed it after starting the project - it's a simple view into a db so I figured I won't need any custom wdgets..
I believe that may be the problem. Yes, it is necessary to recompile the Widgetset. Are you using a Maven multi-module project as the one that can be generated from the Vaadin Maven Plugin?
My experience: When I started out with Vaadin I added add-ons manually by editing the POMs. That turned out to be a bad idea as I had misunderstood in which sub-module an add-on should be added. Now I let the NetBeans IDE Vaadin Plugin do the work and that somehow works a lot better even if its still just some Maven POM stuff that gets changed.
Oren Geva: I don't have a custom widgetset, I don't remember exactly, but I believe I removed it after starting the project - it's a simple view into a db so I figured I won't need any custom wdgets..
Nah, but you'll (sooner or later) need to add Add-Ons to your project and these should be part of your widgetset compilation.
If you use the Vaadin Maven multi-module archetype then you'll get the following modules auto-generated as your project:
fabulousapp - Parent
fabulousapp - production
fabulousapp - ui
fabulousapp - widgetset
ui is where you have all your code.
When you use the IDE plugin to add Add-Ons they effectively gets added as a dependency on your widgetset POM, not your ui POM. So even if don't intend to customize the widgetset you shouldn't remove the widgetset module.
Thanks Peter. That did te trick.
I just added the .gwt.xml file under resources and added a @WidgetSet annotation to the UI class, compiled one and evoila!
It's not really a complex project, just replacing some old php stuff I wrote years ago and can barely understand now :-)
It's just an internal tool using for easy viewes and filtering of a simple db, I really don't expect adding a lot to it.