-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a Spring based project with ZK UI. The pattern used is MVC and the basic structure of project is following: 1) Controller named 'resultController.java' and this java class is declared as resultController in it's spring xml bean definition. 2) The zk file named 'XYZ.zul' with controller attached via apply="${resultController}" 3) resultController has a parameter named 'myParam' and it'svalue is set by getter-setter in spring. 4) Current Implementation of XYZ.zul file has Google Analytics Script Implementation. This script function is inserted in the end of zul file, just before closing ZK tag. This has static analytics Id mentioned in there.
Issue:- I Need to change the static id 'UA-1234567-8' into environment based Id. only way I can think of is to fetch something like 'resultController.myParam' in the script function of zul file.
<zk>
<panel id="MyResultsComponent" apply="${resultController}" height="100%" width="100%" sclass="design-results">
<panelchildren>
<div id="printRoot" height="100%" width="100%">
<iframe id="keepHeartBeat" width="0px" height="0px" />
<label id="lblMessage" visible="false" />
</grid>
</div>
</panelchildren>
</panel>
<style
src="~./org/java/work/ui/results/Results.css" />
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script', 'removing_the_link_as_it_is_not_allowed_in_forums' ,'ga');
ga('create', 'UA-1234567-8', 'auto');
ga('set', 'page', '/XYZ.zul');
ga('send', 'pageview');
</script>
</zk>
I tried multiple ways of doing it but could not get it working. please suggest some ideas.
Thanks
provided your resultController.getMyParam()
method returns the correct value, you can evaluate an EL expression inside the script source like this:
...
ga('create', '${resultController.myParam}', 'auto');
...
I could imagine that resultController
has a prototype bean scope which would result in a new instance every time ${resultController...} is evaluated.
If that's a problem you can also store your myParam
value in a ZK scope:
e.g. execution
for the current request or page
, desktop
, session
illustrated here
http://zkfiddle.org/sample/16qvrth/1-outputting-scoped-attributes-into-a-script
Unfortunately you didn't mention what you already tried so I can't comment on that.
Asked: 2020-01-07 22:17:10 +0800
Seen: 8 times
Last updated: Jan 08 '20