psisodia
psisodia

Reputation: 1177

ZK Event listener not removed from any component using removeEventListener

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?

Upvotes: 0

Views: 1294

Answers (1)

Nabil A.
Nabil A.

Reputation: 3400

Please keep in mind, that your EventListener instance must return true,
if it is the parameter of Object#equal called for the former added listener.

EventListener evl;

@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
    Selectors.wireComponents(view, this, false);
    exitButton.addEventListener("onClick", evl = new EventListener<Event>() {

        public void onEvent(Event evt) throws Exception {
            Messagebox.show("adddingggg");
        }
    });
}

@GlobalCommand
public void disable() {
    if(exitButton.removeEventListener("onClick", evl))
            Messagebox.show("success");
}

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.

Upvotes: 1

Related Questions