Hi Bronius, You're welcome!
Yes, the usage you performed is the intended one. In your case however, maybe you can optimize it, because when a menu-item is clicked, both IMenuItem#onClick() and Menu#onClick() are triggered (in that order). So instead of a 'switch' statement in Menu#onClick(), you can implement the IMenuItem(s)#onClick(). For instance, if you extend the ContextMenu to a dedicated class (embedding the selectedLink member, the menu-items and their #onClick), then you'll have a nicer code IMO... Thanks & best regards, Sebastien. On Mon, Jun 17, 2013 at 1:58 PM, bronius <keptavi...@gmail.com> wrote: > Hi Sebastien, > > Thats great news, I prefer to use library version as it has a lot of > advantages over rolling my own solution. I tried yours and it works fine > for > me. I think example of how to recognize which link was clicked in demo > would > be helpful for others, as context menu will certainly need this for real > world scenario. Here how I did it (let me know if thats how its intended to > use): > final ContextMenu menu = new ContextMenu("menu", Arrays.asList(menuItem1, > menuItem2, menuItem3, menuItem4)) { > > private static final long serialVersionUID = 1L; > > private AjaxFallbackLink<User> selectedLink = null; > > @SuppressWarnings("unchecked") > @Override > protected void onContextMenu(AjaxRequestTarget target, > Component > component) > { > selectedLink = ((AjaxFallbackLink<User>)component); > } > > @Override > public void onClick(AjaxRequestTarget target, IMenuItem item) > { > switch (item.getTitle().getObject()) { > case "Context menu 1": > if (selectedLink != null) { > selectedLink.onClick(target); > } > break; > case "Context menu 2": > System.out.println("Clicked " + > item.getTitle().getObject() + " on " + > selectedLink.getModelObject().getNickname()); > break; > case "Context menu 3": > System.out.println("Clicked " + > item.getTitle().getObject() + " on " + > selectedLink.getModelObject().getNickname()); > break; > case "Context menu 4": > System.out.println("Clicked " + > item.getTitle().getObject() + " on " + > selectedLink.getModelObject().getNickname()); > break; > } > } > }; > > Big thanks and best regards! :) > > bronius >