How to get web application attribute in javascript? [closed]

asked 2018-04-17 22:43:10 +0800

guiperg gravatar image guiperg
3 1

updated 2018-04-17 22:47:39 +0800

Hello, I have a java class that implements WebAppInit and sets an attribute to zk's WebApp object.

I'm able to recover this attribute in a .zul page using EL and if I create a script tag I can use it without problems:


But the problem is that I want to put this script in a .js file and when I do this the EL is not processed.

Is there a way to achieve this? It doesn't need to be with EL, it could be using a ZK javascript object or something like that.

Thanks in advance!

delete flag offensive retag edit

The question has been closed for the following reason "the question is answered, right answer was accepted" by cor3000
close date 2018-04-19 12:37:00

2 Answers

Sort by ยป oldest newest most voted

answered 2018-04-18 20:52:02 +0800

cor3000 gravatar image cor3000
3922 1 7
ZK Team

I should have read your question more carefully... you can add pre-process JS files (and other resources) using the DSP servlet which will interpolate EL-expressions.

Hopefully last updated example: http://zkfiddle.org/sample/6r4eqk/4-EL-to-JS

By default the DSP servlet is not enabled, here the related documentation.

link publish delete flag offensive edit

answered 2018-04-18 20:41:45 +0800

cor3000 gravatar image cor3000
3922 1 7
ZK Team

Hi here a simple example showing 2 variants http://zkfiddle.org/sample/6r4eqk/1-EL-to-JS

One using a client side listener w:onBind another one using a custom client side widget attribute w:profile.

I personally prefer the w:onBind since it guarantees the div is rendered when the listener invokes. E.g. a dynamically added div would call w:onBind later.

Whereas afterMount is more global and invokes after the page rendering is done. Dynamic changes are not covered.

However in both cases the EL is expanded into the JS string. Note the single quotes around the EL to form a valid JS string.

I hope this helps... Other alternatives exist, if you need something more specific let me know.

link publish delete flag offensive edit


I added a 3rd option using <script content="..."/> http://zkfiddle.org/sample/6r4eqk/2-EL-to-JS

cor3000 ( 2018-04-18 20:43:55 +0800 )edit

even funnier I just noticed your way should also work http://zkfiddle.org/sample/6r4eqk/3-EL-to-JS

cor3000 ( 2018-04-18 20:45:51 +0800 )edit

Question tools

1 follower



Asked: 2018-04-17 22:43:10 +0800

Seen: 4 times

Last updated: Apr 18