Closed nautavis closed 3 years ago
Hi,
The problem here is that you pass the information in onOpen
, but it is too late.
IMO, the best option is to send the information when you get it and pass it to the ContextMenu
using the event bus and a customized payload.
When you get the info (considering you know the contextMenu, other you can use bubble or breadth):
@Override
public void onClick(AjaxRequestTarget target) {
BroadcastUtils.exact(contextMenu, new MenuItemPayload(target, "my title"));
}
In the context menu, receive the event:
@Override
public void onEvent(IEvent<?> event) {
super.onEvent(event);
if (event.getPayload() instanceof MenuItemPayload) {
MenuItemPayload payload = (MenuItemPayload) event.getPayload();
MenuItem item = (MenuItem) this.getItemList().get(1);
item.setTitle(Model.of(payload.getTitle()));
this.reload(payload.getHandler());
}
}
The payload would look like:
static class MenuItemPayload extends HandlerPayload {
private String title;
public MenuItemPayload(IPartialPageRequestHandler handler, String title) {
super(handler);
this.title = title;
}
public String getTitle() {
return title;
}
}
In the future please either the Google Forum (or even the Wicket ML) for questions. Github issues is for... issues.
Works perfectly, thank you very much.
I am sending the broadcast now from a preceding mousedown
handler, this way it is possible to set the menu item states depending on whether the mouse click is coming from empty space in scheduler or an actual event.
Sorry for posting this question here instead of the forum or mailing list.
Hallo all,
with a custom
JQueryAjaxBehavior
used innewOnOpenAjaxBehavior
I am detecting, on which event a user clicked in the Scheduler and pass this information to theonOpen
method. Here I would like to enable/disable certainIMenuItem
entries, based on the clicked entry, right before the context menu will be shown. The model value is updated andisEnabled
is called, but the menu items doesn't change their state in GUI. Callingreload(target)
here is not an option because it re-renders the wholeContextMenu
.What would be the best approach for changing the enabled state at
onOpen
phase just before showing the items to the user?