real time update value on zul file with java timer

asked 2022-10-21 13:14:27 +0800

nome gravatar image nome
7 2

updated 2022-10-31 10:59:34 +0800

hawk gravatar image hawk
3073 1 5
http://hawkphoenix.blogsp... ZK Team

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;

    public void run() {
        if (seconds <= MAX_SECONDS) {
            System.out.println("Seconds = " + seconds);

            /* code crashed here */
            mysecond = String.valueOf(seconds);

        } else {
timer.schedule(task, 0, 1000);
delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2022-10-31 11:18:30 +0800

hawk gravatar image hawk
3073 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2022-11-07 08:54:09 +0800

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).

notify change a java bean

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.

link publish delete flag offensive edit


Hi hawk appreciate your guide. I try it but no change to success.

nome ( 2022-11-04 09:23:56 +0800 )edit

Could you describe more details? What have you tried? What's your code and the error? Otherwise, it's hard to help you.

hawk ( 2022-11-07 08:55:21 +0800 )edit

you can also use this example: http://books.zkoss.org/wiki/SmallTalks/2015/January/SimplifyLongOperationHandlings

hawk ( 2022-11-07 08:56:12 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2022-10-21 13:14:27 +0800

Seen: 9 times

Last updated: Nov 07

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