From Documentation

Jump to: navigation, search

Stop.png This documentation is for an older version of ZK. For the latest documentation please click here.


Communications among pages in the same desktop is straightforward. First, you can use attributes to share data. Second, you can use event to notify each other.


Each component, page, desktop, session and Web application has an independent map of attributes. It is a good place to share data among components, pages, desktops and even sessions.

In zscript and EL expressions, you could use the implicit objects: componentScope, pageScope, desktopScope, sessionScope, requestScope and applicationScope.

In Java , you could use "setAttribute()","removeAttribute()" and "getAttribute()" to share data. Another way is using the scope argument to identify which scope you want to access. (In the following example, assuming comp is a component.)

 comp.getAttribute("some", comp.DESKTOP_SCOPE);
 comp.getDesktop().getAttribute("some"); //is equivalent to previous line

Relevant api includes setAttribute, getAttribute, removeAttribute.

In zscript, you can use call such api through implicit objects. For example,


Note that desktop setAttribute will be saved at desktopScope. In EL, you can use "[ ]" operator as the key to retrieve element of map.

Post and Send Events

You could communicate among pages in the same desktop. The way to communicate is to use the postEvent or sendEvent to notify a component in the target page.

 Events.postEvent(new Event("SomethingHappens",

You can also pass object by event. The third parameter in postEvent will be put into You can encapsulate data you want to pass in the object. In the following example, window's title will be set to "this will be send".

<window use="MyWindow">
    Events.postEvent("onTest", self, "this will be send");    

And is as follow,

import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Window;

public class MyWindow extends Window {
	public void onTest(Event evt){

Note: These api has to take care about component life cycle, if you use these api outside ZK event handler, please refer to server push.
