Revision history [back]

click to hide/show revision 1
initial version

asked 2018-01-02 14:27:30 +0800

adilov gravatar image adilov

How to notify change from anonymous class (Listener)

@Command
public void someMethod() {
  final Object bean = this;
  EventListener<ClickEvent> clickListener = new EventListener<Messagebox.ClickEvent>() {
    public void onEvent(ClickEvent event) throws Exception {
      if(Messagebox.Button.YES.equals(event.getButton())) {
        // ...
        BindUtils.postNotifyChange(null, null, bean, "yourIDhere");
      }
    }
};

Messagebox.show("Question?", "Title", new Messagebox.Button[]{Messagebox.Button.YES, Messagebox.Button.NO }, Messagebox.QUESTION, clickListener);
}

Just wanted to share a "trick" that I had to use... If you have anonymous class, e.g. listener as in the code above, and you want to notify for a change, the @NotifyChange annotation will not help you. Or it just didn't work in my case - it doesn't matter if it's above the "delete()" method or above the "onEvent". In this case the "BindUtils.postNotifyChange" can be used, BUT the bean reference must be passed as a parameter, initialized outside the anonymous class.

How to notify change from anonymous Local class (Listener)

@Command
public void someMethod() {
  final Object bean = this;
  EventListener<ClickEvent> clickListener = new EventListener<Messagebox.ClickEvent>() {
    public void onEvent(ClickEvent event) throws Exception {
      if(Messagebox.Button.YES.equals(event.getButton())) {
        // ...
        BindUtils.postNotifyChange(null, null, bean, "yourIDhere");
      }
    }
};

Messagebox.show("Question?", "Title", new Messagebox.Button[]{Messagebox.Button.YES, Messagebox.Button.NO }, Messagebox.QUESTION, clickListener);
}

Just wanted to share a "trick" that I had to use... If you have anonymous local class, e.g. listener as in the code above, and you want to notify for a change, the @NotifyChange annotation will not help you. Or it just didn't work in my case - it doesn't matter if it's above the "delete()" method or above the "onEvent". In this case the "BindUtils.postNotifyChange" can be used, BUT the bean reference must be passed as a parameter, initialized outside the anonymous class.

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More