Inter-Desktop Communication"
From Documentation
Line 4: | Line 4: | ||
=Desktops in the Same Browser Window= | =Desktops in the Same Browser Window= | ||
+ | |||
+ | In most cases, a browser window has at most one desktop. However, it is still possible to multiple desktops in one browser window: | ||
+ | |||
+ | * Use HTML IFRAME or FRAMESET to integrate multiple ZUML pages | ||
+ | * Use a portal server to integrate multiple ZK portlet | ||
+ | * Assembly multiple ZUML pages at the client, such as [[ZK Developer's Reference/Integration/Use ZK as Fragment in Foreign Templating Framework|this templating technology]] | ||
+ | |||
+ | In this case, you could communicate among desktops by use of an event queue with the group scope. | ||
+ | |||
+ | <source lang="java" high="1"> | ||
+ | EventQueue que = EventQueues.lookup("groupTest", EventQueues.GROUP, true); | ||
+ | que.subscribe(new EventListener() { | ||
+ | public void onEvent(Event evt) { | ||
+ | //receive event from this event queue (within the same group of desktops) | ||
+ | } | ||
+ | }); | ||
+ | </source> | ||
+ | |||
+ | Here is a dumb example: chat among iframes. | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <-- main --> | ||
+ | <window title="main" border="normal" onOK="publish()"> | ||
+ | <zscript> | ||
+ | EventQueue que = EventQueues.lookup("groupTest", "group", true); | ||
+ | que.subscribe(new EventListener() { | ||
+ | public void onEvent(Event evt) { | ||
+ | o.setValue(o.getValue() + evt.getData() + "\n"); | ||
+ | } | ||
+ | }); | ||
+ | void publish() { | ||
+ | String text = i.getValue(); | ||
+ | if (text.length() > 0) { | ||
+ | i.setValue(""); | ||
+ | que.publish(new Event("onGroupTest", null, text)); | ||
+ | } | ||
+ | } | ||
+ | </zscript> | ||
+ | Please type some words into the short textbox, and then you should see every high textbox will append the same words. | ||
+ | <textbox id="i" onChange="publish()"/> | ||
+ | <textbox id="o" rows="6"/> | ||
+ | <separator/> | ||
+ | <iframe src="includee.zul" height="500px" width="30%"/> | ||
+ | <iframe src="includee.zul" height="500px" width="30%"/> | ||
+ | <iframe src="includee.zul" height="500px" width="30%"/> | ||
+ | </window> | ||
+ | </source> | ||
+ | |||
+ | And, this is the ZUML page being referenced (by iframe). | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <!-- includee.zul --> | ||
+ | <window title="frame2" border="normal" onOK="publish()"> | ||
+ | <zscript> | ||
+ | EventQueue que = EventQueues.lookup("groupTest", "group", true); | ||
+ | que.subscribe(new EventListener() { | ||
+ | public void onEvent(Event evt) { | ||
+ | o.setValue(o.getValue() + evt.getData() + "\n"); | ||
+ | } | ||
+ | }); | ||
+ | void publish() { | ||
+ | String text = i.getValue(); | ||
+ | if (text.length() > 0) { | ||
+ | i.setValue(""); | ||
+ | que.publish(new Event("onGroupTest", null, text)); | ||
+ | } | ||
+ | } | ||
+ | </zscript> | ||
+ | <textbox id="i" onChange="publish()"/> | ||
+ | <textbox id="o" rows="6"/> | ||
+ | </window> | ||
+ | </source> | ||
=Desktop in Different Sessions= | =Desktop in Different Sessions= |
Revision as of 11:39, 25 November 2010
Unlike pages, you cannot access two desktops at the same time. You cannot send or post an event from one desktop to another directly, either. Rather, we have to use a event queue with a proper scope, such as group, session or application -- depending on where the other desktop is located.
Desktops in the Same Browser Window
In most cases, a browser window has at most one desktop. However, it is still possible to multiple desktops in one browser window:
- Use HTML IFRAME or FRAMESET to integrate multiple ZUML pages
- Use a portal server to integrate multiple ZK portlet
- Assembly multiple ZUML pages at the client, such as this templating technology
In this case, you could communicate among desktops by use of an event queue with the group scope.
EventQueue que = EventQueues.lookup("groupTest", EventQueues.GROUP, true);
que.subscribe(new EventListener() {
public void onEvent(Event evt) {
//receive event from this event queue (within the same group of desktops)
}
});
Here is a dumb example: chat among iframes.
<-- main -->
<window title="main" border="normal" onOK="publish()">
<zscript>
EventQueue que = EventQueues.lookup("groupTest", "group", true);
que.subscribe(new EventListener() {
public void onEvent(Event evt) {
o.setValue(o.getValue() + evt.getData() + "\n");
}
});
void publish() {
String text = i.getValue();
if (text.length() > 0) {
i.setValue("");
que.publish(new Event("onGroupTest", null, text));
}
}
</zscript>
Please type some words into the short textbox, and then you should see every high textbox will append the same words.
<textbox id="i" onChange="publish()"/>
<textbox id="o" rows="6"/>
<separator/>
<iframe src="includee.zul" height="500px" width="30%"/>
<iframe src="includee.zul" height="500px" width="30%"/>
<iframe src="includee.zul" height="500px" width="30%"/>
</window>
And, this is the ZUML page being referenced (by iframe).
<!-- includee.zul -->
<window title="frame2" border="normal" onOK="publish()">
<zscript>
EventQueue que = EventQueues.lookup("groupTest", "group", true);
que.subscribe(new EventListener() {
public void onEvent(Event evt) {
o.setValue(o.getValue() + evt.getData() + "\n");
}
});
void publish() {
String text = i.getValue();
if (text.length() > 0) {
i.setValue("");
que.publish(new Event("onGroupTest", null, text));
}
}
</zscript>
<textbox id="i" onChange="publish()"/>
<textbox id="o" rows="6"/>
</window>
Desktop in Different Sessions
Version History
Version | Date | Content |
---|---|---|