-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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).
Could you suggest a way to develop it?
(our main problem is that the pages are on different servers..)
Thank you!
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¶m2=value2¶metc=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.
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
<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}));
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.
Asked: 2023-05-24 16:35:23 +0800
Seen: 9 times
Last updated: May 25
zkspringmvc jar licence is GPL ?
Build web application without any zul files
Custom component that extends Textbox does not fire onChange event
java.lang.NullPointerException to update to zk 8.0.1
"Spring Session" + ZK + "Spring core" @Listen method refresh the screen
zk8 client side binding to a viewmodel command seems not to work