Used with the forward Attribute

A window usually consists of several buttons, menu items and other controls. For example,

<window use="MyWindow">
    ...    
    <button label="OK"/>    
    <button label="Cancel"/>    
</window>

When the user clicks the button, the onClick event is sent to the button itself. However, these events are better to process in the window rather than scattering around these buttons. To do that, you can use the forward attribute as follows.

<window use="MyWindow">
    ...    
    <button label="OK" forward="onOK"/>    
    <button label="Cancel" forward="onCancel"/>    
</window>

where the forward attribute of the OK button specifies that the onClick event, if received, shall be forwarded to the space owner (i.e., the window) as the onOK event. Similarly, the onClick event targeting the Cancel button is forwarded as the onCancel event. Thus, you can handle the onOK and onCancel events in the space owner, MyWindow, as follows.

public class MyWindow extends Window {
    public void onOK() {    
        //called when the OK button is clicked (or the ENTER button is pressed)        
    }    
    public void onCancel() {    
        //called when the Cancel button is clicked (or the ESC button is pressed)        
    }    
}

In addition to forward the onClick event to the space owner, you can forward any event to any component with the forward attribute. Refer to the forward Attribute section in the ZK User Interface Markup Language chapter for more details.