0

Issue fetching java parameter in zul

asked 2020-01-07 22:17:10 +0800

mandeep gravatar image mandeep
1 1

updated 2020-01-08 11:24:37 +0800

cor3000 gravatar image cor3000
5069 2 7
ZK Team

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

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-01-08 11:47:07 +0800

cor3000 gravatar image cor3000
5069 2 7
ZK Team

updated 2020-01-08 11:50:39 +0800

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.

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

Follow
1 follower

RSS

Stats

Asked: 2020-01-07 22:17:10 +0800

Seen: 7 times

Last updated: Jan 08

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