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.
ManuBar.MenuItem, selectedItem.getId()
Hi,
I'm following this example: http://demo.vaadin.com/sampler#BasicMenuBar
What I wonder now if there is some more decent way of checking what item that actually is pressed, im looking for something like a switch-statement.
switch(selectedItem.getId()) {
case: 1
new fooHello();
case: 2
new fooGoodbye():
}
and so on.
Is there a more pretty solution than this? Since I'm not sure about the id logic when adding a new item, it doesn't seem to just add up with 1 per item you add (correct me if im wrong though)
Any help is appreciated
Br,
Johan Bergman
You should use Command interface. If you need some id handling you could create your own Command implementing class, which takes an id in constructor. In menuSelected you can check the id.
Hi,
thanks for your reply.
I am using the Command interface, and since I'm having so few items I went for this solution:
final MenuBar.MenuItem file = menubar.addItem("File", null);
file.addItem("Quit", new Command(){
public void menuSelected(MenuItem selectedItem) {
// Do whatever here
}});