-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hello everyone, i have a zk web application that is a backend tool for looking customers in my application.
What i need to achieve, is to fire an event to the zk client (a popup needs to appear in the frontend, which will open another page) from an external application. Basically i need to send an event from the server to all the zk clients opened.
How do i achieve that?
Tried with the eventqueue, but i'm getting "not in an execution" exception...
if you want to notify all users on the server you need to lookup/create an application scoped event queue.
EventQueue eq = EventQueues.lookup("testqueue", "application", true);
It is allowed to publish events to an application (or session) scoped event queue outside an execution.
Here also a short example: If you open this in multiple browsers you'll see how every browser (=different user): receives a notification after a new user joined. The background thread can be any kind of thread. All it needs is a reference to the eventqueue in order to publish events.
EventQueue eq = EventQueues.lookup("testqueue", "application", true);
Thread a = new Thread() {
public void run() {
org.zkoss.lang.Threads.sleep(5000);
eq.publish(new Event("onMyEvent", null, "some_redirect_url"));
}
};
a.start();
eq.subscribe(new EventListener() {
public void onEvent(Event evt) {
alert(evt.getData());
//open your popup based on the url
}
});
Asked: 2016-11-16 08:55:12 +0800
Seen: 29 times
Last updated: Nov 17 '16