1

Im trying to do following:

  1. Send long executing request (I use here Events.echoEvent)
  2. Show modal dialog (Wait...) with "cancel" button
  3. If user press "cancel", dialog is hidded and event method should not be executed.
  4. If user don't press button and wait. event method is called and close wait dialog

How can I do that?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Sarge
  • 79
  • 6

2 Answers2

2

ZK normally does all it's work for a single request on the server in a single thread. Events.echoEvent lets you get around that by finishing the request, and then calling back to the server immediately in a brand new request (and thread). The user's interaction with the client fires off a new request, so that will be a new thread also.

So, in your example above, you will be working with three threads:

  1. for the original request which calls echoEvent
  2. for the new request created by the echoEvent
  3. for the request created when the user clicks 'cancel'

Obviously, the first will be long gone by the time the last two get called, but this is what you need to be thinking about in order to solve your problem.

You'll find plenty of discussion on StackOverflow about getting two threads to interact, or more specifically, getting one thread to interrupt another.

I'll refer you to 'How to stop threads in Java?' where the accepted answer favored sharing some sort of 'stop flag' over directly calling interrupt on a thread.

In your scenario this would play out with the long running process doing it's work while periodically checking the stop flag (a simple boolean). When the user clicks 'Cancel', you just need to flip the flag to true.

Community
  • 1
  • 1
Sean Connolly
  • 5,692
  • 7
  • 37
  • 74
1

You can try

  1. Create a thread to do the long operation as Sean mentioned above (this is an independent thread, not ZK request thread)

  2. Create a timer to check the status of that thread periodically. (this will create a javascript timer to send ajax request periodically at client side)

  3. And customize the busy mask by ZK Client Side programming to add the cancel button. (the button click perform another ajax request)

    Please refer to the similar article at stackoverflow: Override “Processing” in ZK

Edit:

There are some related articles at my blog:

ZK: Customize the mask for showBusy

ZK: Adding abort button to busy mask

ZK: Mask page manually

Community
  • 1
  • 1
benbai123
  • 1,423
  • 1
  • 11
  • 11