-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I'd like to implement a Fire and Forget functionality, for example a <button id='myBtn' onClick='myBtn_onClick()' /> . The myBtn_onClick() event with call another method that runs some reports and then email the report to the user in the background. The key thing is the onClick event should not wait for this background method. Is there a way to do it? Your insight is greatly appreciated...
sample zul:
========
<button id='myBtn' onClick='myBtn_onClick()' />
sample java:
=========
public void myBtn_onClick() throws Exceptions {
this.runReports();//should not wait for the method to complete, should go to the next line and display the Messagebox
// and finish the onClick event
Messagebox.show("Reports are being run and you'll get email notification shortly....");
}//end method
private void runReports() {
//Run some reports and email users once done
}//end method
Please read:
http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/UI%20Patterns/Long%20Operations
The simple approach (if you don't need to inform the user when the work is finished)... call runReports as dedicated Thread:
public void myBtn_onClick() throws Exceptions { new Thread(new Runnable() { public void run() { runReports(); } }).start(); Messagebox.show("Reports are being run and you'll get email notification shortly....");
Cheers, Maik
Asked: 2011-03-31 15:32:13 +0800
Seen: 159 times
Last updated: Apr 01 '11