-
FEATURED COMPONENTS
First time here? Check out the FAQ!
@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 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.
Hi Adilov,
thanks for sharing your 'trick'. In fact it's not a trick but rather the programmatic way to notify change a property. You are right, @NotifyChange can't help you if you call a method yourself, and that's why you correctly found the BindUtils.postNotifyChange() method. When using a local inner class you can reference the outer this like in the example below. No need for an additional variable.
public class SomeViewModel {
@Command
public void someMethod() {
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, SomeViewModel.this, "yourIDhere");
}
}
};
Messagebox.show("Question?", "Title", new Messagebox.Button[]{Messagebox.Button.YES, Messagebox.Button.NO },
Messagebox.QUESTION, clickListener);
}
}
When using Java 8 this isn't even necessary anymore:
@Command
public void someMethod() {
Messagebox.show("Question?", "Title",
new Messagebox.Button[]{Messagebox.Button.YES, Messagebox.Button.NO},
Messagebox.QUESTION,
event -> {
if (Messagebox.Button.YES.equals(event.getButton())) {
// ...
BindUtils.postNotifyChange(null, null, this, "yourIDhere");
}
});
}
Asked: 2018-01-02 14:27:30 +0800
Seen: 22 times
Last updated: Jan 03 '18
MVVM Notifychange works only along with @Command ?
Upload csv files with Zk framework
MVVM Notifychange for bean property not working ?
Create notification icon with zk 7 CE
@NotifyChange not refresh textbox
how can i get data from another page
Notify Form of property change