I am having trouble removing an event listener from tab and toolbarbutton.
I have added an eventlistener to a toolbarbutton, then after doing some saving part I can’t remove the listener.
exitButton is a toolbarbutton.
Both methods are in same class. But the first Time exitButton has some different logic on onClick event but when I save my data and call disable() method via globalcommand to remove onClick event listener.
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
Selectors.wireComponents(view, this, false);
exitButton.addEventListener("onClick", new EventListener<Event>() {
public void onEvent(Event evt) throws Exception {
Messagebox.show("adddingggg");
}
});
}
@GlobalCommand
public void disable() {
exitButton.removeEventListener("onClick", new EventListener<Event>() {
public void onEvent(Event evt) throws Exception {
Messagebox.show("remocvee");
}
});
}
How can I remove the Event Listener after a save?
Please keep in mind, that your
EventListenerinstance must returntrue,if it is the parameter of
Object#equalcalled for the former added listener.This will remove the EventListener, and show message if it was successful.
You problem was that you created a new object so it is not equal to the old one.