-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all. I am getting across an issue I'm not able to figure out how it can happen. From a (custom) component onClick event I am creating a EventQueue in order to publish a Event other pages can listen to. After the event publishing I send a redirect to another page. This is the code:
private EventListener eventListener = new EventListener() {
public void onEvent(Event event) throws Exception {
if (Events.ON_CLICK.equals(event.getName())) {
doProcess();
}
}
};
public void doProcess() {
EventQueue eq =
EventQueues.lookup("createInnerWindowQueue", EventQueues.SESSION, true);
eq.publish(new Event("createInnerWindow", this));
Executions.getCurrent().sendRedirect("/page.zul");
}
On the new page (page.zul) there is a Div component which has a Composer like this:
public class DivComposer implements Composer<Div> {
private EventQueue eq = EventQueues.lookup("createInnerWindowQueue", EventQueues.SESSION, false);
public void doAfterCompose(final Div comp) throws Exception {
if (eq != null) {
eq.subscribe(new EventListener() {
public void onEvent(Event event) throws Exception {
// here the code to process the event
}
}, true);
}
}
}
I tried both syncronous and asyncronous events. The subscribe statement is always executed, however the onEvent method is never fired. This code seems to me in line with the samples on reference manuals. What am I missing?
/Adriano
You are first publishing an event, and then adding a subscriber. That doesn't work because there is no-one listening when the event is published, so it is simply discarded.
The EventQueue only publishes events to current subscribers, and it doesn't store them if nobody is listening. That is how publish-subscribe -style queues work in general.
Asked: 2013-07-01 09:45:47 +0800
Seen: 14 times
Last updated: Jul 01 '13