Subscribe to EventQueues"

From Documentation
m (Created page with "{{ZKDevelopersReferencePageHeader}} =Subscribe to EventQueue= =Version History= {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content |- | 6.0.1 | April...")
 
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
=Subscribe to EventQueue=
+
=Subscribe to EventQueues=
 +
You can subscribe a method (as if in an EventListener) to an [[ZK_Developer's_Reference/Event_Handling/Event_Queues | EventQueue]] by annotate it with <javadoc>org.zkoss.zk.ui.select.annotation.Subscribe</javadoc>. For example,
  
 +
<source lang="java">
 +
@Subscribe("queue1")
 +
public void method1(Event event) {
 +
// this method will be called when EventQueue "queue1" of Desktop scope is published
 +
Object data = event.getData();
 +
Component target = event.getTarget();
 +
}
 +
public void publish() {
 +
EventQueue<Event> eq = EventQueues.lookup("queue1", EventQueues.DESKTOP, true);
 +
eq.publish(new Event("onMyEvent", component, data));
 +
}
 +
</source>
  
 +
In the example above, when you publish an event in the EventQueue, the subscribed method will be called. It is a useful mechanism to communicate with other composers. See also
 +
 +
 +
&nbsp;
 +
==EventQueue Scope==
 +
You can subscribe to EventQueue of different scope.
 +
 +
<source lang="java">
 +
@Subscribe(value = "queue2", scope = EventQueues.SESSION)
 +
public void method2(Event event) {
 +
// this method will be called when EventQueue "queue2" of Session scope is published
 +
}
 +
public void publish() {
 +
EventQueue<Event> eq = EventQueues.lookup("queue2", EventQueues.SESSION, true);
 +
eq.publish(new Event("onMyEvent", component, data));
 +
}
 +
</source>
 +
 +
Available scopes are: Desktop, Group, Session, Application. Note that Group scope requires ZK EE. See also <javadoc>org.zkoss.zk.ui.event.EventQueues</javadoc>.
 +
 +
 +
&nbsp;
 +
==Subscriber Method Parameter==
 +
The method which subscribes to the EventQueue takes either no parameter, or one parameter of type Event.
 +
 +
<source lang="java">
 +
@Subscribe("queue3")
 +
public void method3() { // the event parameter can be omitted
 +
// ...
 +
}
 +
</source>
  
 
=Version History=
 
=Version History=

Revision as of 03:47, 10 April 2012


Subscribe to EventQueues


Subscribe to EventQueues

You can subscribe a method (as if in an EventListener) to an EventQueue by annotate it with Subscribe. For example,

@Subscribe("queue1")
public void method1(Event event) {
	// this method will be called when EventQueue "queue1" of Desktop scope is published
	Object data = event.getData();
	Component target = event.getTarget();
}
public void publish() {
	EventQueue<Event> eq = EventQueues.lookup("queue1", EventQueues.DESKTOP, true);
	eq.publish(new Event("onMyEvent", component, data));
}

In the example above, when you publish an event in the EventQueue, the subscribed method will be called. It is a useful mechanism to communicate with other composers. See also


 

EventQueue Scope

You can subscribe to EventQueue of different scope.

@Subscribe(value = "queue2", scope = EventQueues.SESSION)
public void method2(Event event) {
	// this method will be called when EventQueue "queue2" of Session scope is published
}
public void publish() {
	EventQueue<Event> eq = EventQueues.lookup("queue2", EventQueues.SESSION, true);
	eq.publish(new Event("onMyEvent", component, data));
}

Available scopes are: Desktop, Group, Session, Application. Note that Group scope requires ZK EE. See also EventQueues.


 

Subscriber Method Parameter

The method which subscribes to the EventQueue takes either no parameter, or one parameter of type Event.

@Subscribe("queue3")
public void method3() { // the event parameter can be omitted
	// ...
}

Version History

Last Update : 2012/04/10


Version Date Content
6.0.1 April 2012 @Subscribe was introduced.



Last Update : 2012/04/10

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.