you can also use this example: http://books.zkoss.org/wiki/SmallTalks/2015/January/SimplifyLongOperationHandlings
hawk ( 2022-11-07 08:56:12 +0800 )edit-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi guys,
I need your help. How can I update real time value on zul file by using java timer? the sample code below, it crashed when update value by real time to zul file.
TimerTask task;
task = new TimerTask() {
private final int MAX_SECONDS = 100;
@Override
@NotifyChange("mysecond")
public void run() {
if (seconds <= MAX_SECONDS) {
System.out.println("Seconds = " + seconds);
/* code crashed here */
mysecond = String.valueOf(seconds);
BindUtils.postNotifyChange(this,"mysecond");
seconds++;
} else {
cancel();
}
}
};
timer.schedule(task, 0, 1000);
What error message do you see?
I suppose it might be:
Exception in thread "Timer-0" java.lang.IllegalStateException: Not in an execution at org.zkoss.zk.ui.event.impl.EventQueueProviderImpl.lookup(EventQueueProviderImpl.java:67) at org.zkoss.zkmax.ui.event.impl.EventQueueProviderImpl.lookup(EventQueueProviderImpl.java:57) at org.zkoss.zk.ui.event.EventQueues.lookup(EventQueues.java:130) at org.zkoss.bind.BindUtils.postNotifyChange(BindUtils.java:69) at org.zkoss.bind.BindUtils.postNotifyChange(BindUtils.java:58)
If so, since postNotifyChange()
involves sending a response to a browser, you need to call it in a command method (or an event listener).
regarding BindUtils.postNotifyChange(this,"mysecond");
The this
is the anonymous class of TimerTask
. It's not a ViewModel nor a Java bean, so I think you notify the wrong target.
You should put @NotifyChange
on a command method.
Since writing in MVVM pattern requires to know more details about framework behavior, I will suggest you to read http://books.zkoss.org/wiki/ZKGettingStarted/GetZKUpandRunningwithMVVM
Or it's better to start from MVC pattern first if you are new to ZK.
you can also use this example: http://books.zkoss.org/wiki/SmallTalks/2015/January/SimplifyLongOperationHandlings
hawk ( 2022-11-07 08:56:12 +0800 )editAsked: 2022-10-21 13:14:27 +0800
Seen: 9 times
Last updated: Nov 07 '22