Event Forwarding"

From Documentation
(Created page with '{{ZKComponentReferencePageHeader}} = Overview = For easy programming, ZK does not introduce any complex event flow. When an event is sent to a target component, only the event l…')
 
Line 25: Line 25:
  
 
= Event Forwarding in ZUL =
 
= Event Forwarding in ZUL =
 +
 +
Event forwarding can be done with the forward attribute in ZUL. For example,
 +
 +
<source lang="xml">
 +
<window>
 +
<button label="Save" forward="onSave"/>
 +
<button label="Cancel" forward="onCancel"/>
 +
</window>
 +
</source>
 +
 +
Then, <tt>window</tt> will receive the <tt>onSave</tt> event when the Save button is clicked.
 +
 +
With this approach we could introduce an abstract layer between the event and the component. For example, <tt>window</tt> needs only to handle the <tt>onSave</tt> event without knowing which component causes it. Therefore, you could introduce another UI to trigger onSave without modifying the event listener. For example,
 +
 +
<source lang="xml">
 +
<menuitem label="Save" forward="onSave"/>
 +
</source>
  
 
{{ZKComponentReferencePageFooter}}
 
{{ZKComponentReferencePageFooter}}

Revision as of 09:56, 24 August 2010


Overview

For easy programming, ZK does not introduce any complex event flow. When an event is sent to a target component, only the event listeners registered for the target component will be called. It is the application's job to forward an event to another component if required (by the application).

For example, you might have a menu item and a button to trigger the same action, say, opening a dialog, and then it is more convenient to have a single listener to open the dialog, and register the listener to the main window rather than register to both the menu item and the button.

Event Forwarding in Java

Forwarding an event is straightforward: just post or send the event again. However, there is a better way: composer. The composer can be the central place to handle the events. For example,

public class FooComposer extends GenericForwardComposer {
   public void onClick$menuitem() {
     openDialog();
   }
   public void onClick$button() {
     openDialog();
   }
   private void openDialog() {
     //whatever you want
   }
}

Event Forwarding in ZUL

Event forwarding can be done with the forward attribute in ZUL. For example,

<window>
	<button label="Save" forward="onSave"/>
	<button label="Cancel" forward="onCancel"/>
</window>

Then, window will receive the onSave event when the Save button is clicked.

With this approach we could introduce an abstract layer between the event and the component. For example, window needs only to handle the onSave event without knowing which component causes it. Therefore, you could introduce another UI to trigger onSave without modifying the event listener. For example,

	<menuitem label="Save" forward="onSave"/>



Last Update : 2010/08/24

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