Communication between zul on different servers

asked 2023-05-24 16:35:23 +0800

pocca gravatar image pocca

updated 2023-05-24 18:15:43 +0800

Good morning everybody,

we have two different webapps, AppA and AppSub, deployed on different servers.

In zul page of AppA (which uses MVVM pattern, let's call it appA.zul) we would to include a zul page of AppSub (also this page uses MVVM pattern, let's call it appSub.zul).

  • appA.zul should pass a set of parameters to appSub.zul
  • appSub.zul should notify an event or a set of results to appA.zul

Could you suggest a way to develop it?

(our main problem is that the pages are on different servers..)

Thank you!

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted

answered 2023-05-25 11:22:34 +0800

MDuchemin gravatar image MDuchemin
2310 1 6
ZK Team

Hey there.

Regarding sending parameters:

That one is easy. Just pass them as URL parameters. Whether using iframe or ZK embedded, just make the link something like http://myserver:myport/mycontext/mypage.zul?param1=value1&param2=value2&parametc=valueetc

From there, you can retrieve the params in the ViewModel, either through the implicit variables param and args in zul file, or in viewModel using queryParam annotation.

Regarding sending events back to the outer page: I can see tow ways to approach this type of structure.

  • First, the one I would actually do: Communication through client-side events.

Note: this will require passing data to the client, which can be inspected through the developer tools, so ideally you'd want to send the strict minimum information for these parameters, and avoid sending anything that you would not want the user to be able to see.

In this case, I'd use either ZK embedded or an iFrame to include the subApp page into the main page. Using iframe, you'll need the extra step of setting up a communication channel between the outer window and the iframe window. This can be done with the window postMessage API

With Embedded mode, both the inner page and outer page will be in the same JavaScript context already, so you can just communicate directly between them.

Once you have a communication channel established (either directly with embedded, or through postMessage with iframe), you can send a custom event directly from the client to an arbitrary component

For example, assuming you have a

component in your page, you can create a custom event on it to trigger a command such as:

<div id="myTarget" onCustomInterApp="@command('myCommandName',data=event.data) />

From there, you can use JS to trigger this custom event directly from client-side:

// divWgt is the widget for the div, retrieved with zk.$()
// for example here, we can select by id with zk.$('$myTarget')
zAu.send(new zk.Event(divWgt, "onCustomInterApp", {value1: 'my data'}, {toServer:true}));
  • The other option is to do server-side communication. This is less convenient, and require that both servers be able to communicate with each-other. The only positive to that approach is that the event data is not passed to the client. As a result, this is only useful if you absolutely need to hide such data from client-side.

ZK Framework itself is not a server-to-server communication framework, so actually communicating between server would be up to you.

In order to trigger an update to the client once you receive a server-side event, you'll need to use server-push.

Again, this way to approach the problem is much more complicated than using the already established common space at client-side, so I only mention it in case the data you need to pass back and forth is confidential.

And even then, encrypting/decrypting the data before passing it as a parameter or as event data would be much more efficient.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2023-05-24 16:35:23 +0800

Seen: 6 times

Last updated: May 25

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More