Problem description:
If multiple group scoped event queues were created, only the event published to the first created event queue is handled by subscribed event listener. Events published to subsequently created event queues are ignored.
Reproducing step:
1. open "events.zul"
2. click on the button inside iframe
-> events were published to both group scoped event queues
--> however, only the event listener subscribed to queue1 is reached
Reproducing sample:
events.zul
<div apply="pkg$.SubscribeController"> <button id="publish1">publish to queue 1</button> <button id="publish2">publish to queue 2</button> <iframe src="iframe.zul"/> <label id="label1"/> <label id="label2"/> </div>
iframe.zul
<div apply="pkg$.PublishController" style="border: 1px dashed red"> Inside iFrame <button id="both">publish to both queues</button> </div>
SubscribeController.java
package pkg$; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventQueue; import org.zkoss.zk.ui.event.EventQueues; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.annotation.Listen; import org.zkoss.zk.ui.select.annotation.Wire; import org.zkoss.zul.Label; @SuppressWarnings("serial") public class SubscribeController extends SelectorComposer<Component> { // public static final String EQ = EventQueues.SESSION; public static final String QUEUE_SCOPE = EventQueues.GROUP; public static final String EQ_NAME_1 = "eq1"; public static final String EQ_NAME_2 = "eq2"; private EventQueue<Event> queue1; private EventQueue<Event> queue2; @Wire private Label label1; @Wire private Label label2; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); queue1 = EventQueues.lookup(EQ_NAME_1, QUEUE_SCOPE, true); queue1.subscribe( new EventListener<Event>() { public void onEvent(Event ev) { label1.setValue(ev.getName()); } }); queue2 = EventQueues.lookup(EQ_NAME_2, QUEUE_SCOPE, true); queue2.subscribe( new EventListener<Event>() { public void onEvent(Event ev) { String msg = (String) ev.getName(); label2.setValue(msg); } }); } @Listen("onClick = #publish1") public void doPublish1() { queue1.publish(new Event("to queue1")); } @Listen("onClick = #publish2") public void doPublish2() { queue2.publish(new Event("to queue2")); } }
PublishController.java
package pkg$; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventQueue; import org.zkoss.zk.ui.event.EventQueues; import org.zkoss.zk.ui.select.SelectorComposer; import org.zkoss.zk.ui.select.annotation.Listen; @SuppressWarnings("serial") public class PublishController extends SelectorComposer<Component> { private EventQueue<Event> queue1; private EventQueue<Event> queue2; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); queue1 = EventQueues.lookup(SubscribeController.EQ_NAME_1, SubscribeController.QUEUE_SCOPE, false); queue2 = EventQueues.lookup(SubscribeController.EQ_NAME_2, SubscribeController.QUEUE_SCOPE, false); } @Listen("onClick = #both") public void doPublishBoth() { queue1.publish(new Event("to queue1")); queue2.publish(new Event("to queue2")); } }