Showing progress of action of Messagebox

asked 2023-06-24 17:13:56 +0800

newborn gravatar image newborn
3 2

updated 2023-06-26 09:46:11 +0800

Hello everyone,

I am new to ZK and I'm currently developing a page with a Messagebox that prompts the user with a "Yes" or "No" question. The ensuing action, following a "Yes" response, is quite demanding and tends to require a considerable amount of time - approximately 1 to 2 minutes. Given the duration of this action, it may potentially mislead the user into thinking that the page is not responding.

In an attempt to rectify this, I sought to introduce a ProgressMeter. This would provide the user with an estimation of the progress made during the process. However, I encountered an issue. It appears that all UI updates can only be executed upon the completion of the "onEvent". This subsequently rendered the ProgressMeter ineffective.

protected Window window;    //Window that contain the Progressmeter 
protected Progressmeter meter;

public void action() {
    Messagebox.show("Confirm?", MESSAGE.INFORMATION, Messagebox.YES | Messagebox.NO, Messagebox.QUESTION, new EventListener<Event>() {
        public void onEvent(Event event) {
        if (event.getName().equals(Messagebox.ON_YES)) {
                for(int i:k){
                    //Demanding functions...
                    BindUtils.postNotifyChange(null, null, this, "*");
    // Codes here would run before "onEvent"

Invoking the functions subsequent to the execution of MessageBox.show seemed like a viable solution, but this attempt fell short of expectation. This was because MessageBox.show operates in a manner such that it runs last in sequence.

Any help or advice on this matter would be greatly appreciated.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-06-27 20:31:12 +0800

MDuchemin gravatar image MDuchemin
2505 1 6
ZK Team

Hey there,

Regarding the messagebox: The onEvent eventListener of the messagebox is only invoked when the messagebox is closed by the user. In order to do what you describe, you need "ongoing updates" to be sent while your process is ongoing at server side.

Abstract info first: A ZK server communicates with the client browser through requests. In order to update the browser, you need to have an open request established by the client to which you can reply to. This is called an Execution (in ZK context).

There are two different approaches you can consider for this type of requirement (updating the browser while the server does a thing):

1 - brute force updates with a timer : the timer component is a utility component which you can add to a page. It doesn't draw any element in the browser (it doesn't create a div or other elements), but it will fire events periodically, in which you can perform an action which updates the client.

Here's the most basic sample of what that would look like: https://zkfiddle.org/sample/35ug2em/5-timer-progressmeter

Note: I've used zscript here for brievety. Don't use zscript in real life, it's just for the example. Use a composer or viewModel depending on your preferred pattern.

What this does: The timer establish a request (an event) from client-side every X milliseconds (as defined in the delay attribute of the timer). If you set the repeat attribute to true, it just keeps repeating (sending an new event) every time the delay repeats. In that onTimer event, you can update the client, because the client is sending a request and waiting for a response.

Pros: it's easy to setup, doesn't require extra config, simple request / response cycle.

Cons: timing is controlled by the client. If you want to "check every second" for updates, but you have nothing to update for 1mn, that means that your first 59 requests will return nothing. Also, you need to manage the timer component (start it, close it after you are done) so that it doesn't always run.

2 - Server push

Server push is a feature that allows the server to keep an open connection permanently with the client. If the server needs to send an update at any time, it can "activate" the desktop which is tied to that server push and send an update. That consumes the open connection (by sending a response). Once the client has processed the first response, it establishes another open connection for the server to consume in the future.

Pros: The server decides when to consume the server push connection. This means that you don't need to ping the server over time. The server can "act" directly when a given event happen at server side, and send an update to the client.

Cons: Server push is a little more complicate to setup / use that just a simple event. (see documentation above)

link publish delete flag offensive 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

1 follower



Asked: 2023-06-24 17:13:56 +0800

Seen: 8 times

Last updated: Jun 27 '23

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