1

I have a zul file running on a localserver (localhost:8080) that uses a JavaScript file stored in a separate local server (localhost:3000):

<script type="text/javascript" src="http://localhost:3000/javascript/bower_components/angular/angular.js"></script>

If I want to place the url of the separate local server in a properties file, what is the best approach for doing so? I have tried to add a placeholder:

<script type="text/javascript" src="${graph.widget.url}/javascript/bower_components/angular/angular.js"></script>

then add in the properties file:

graph.widget.url=http://localhost:3000

and then add in the zk.xml file:

<system-config>
    <label-location>file:///home/asd/resources/dev-common.properties</label-location>
</system-config>

but somehow it doesn't work: it looks for http://localhost:8080/javascript/bower_components/angular/angular.js (the local server where the application runs) instead of http://localhost:3000/javascript/bower_components/angular/angular.js. What am I doing wrong?

halfer
  • 19,824
  • 17
  • 99
  • 186
Anto
  • 4,265
  • 14
  • 63
  • 113

1 Answers1

1

You have to prefix the key with the labels segment.

<script 
    type="text/javascript" 
    src="${labels.graph.widget.url}/javascript/bower_components/angular/angular.js">
</script>

Source: https://www.zkoss.org/wiki/ZUML_Reference/EL_Expressions/Implicit_Objects/labels

flo
  • 9,713
  • 6
  • 25
  • 41
  • I do get the following exception: org.zkoss.zel.ELException: Problems calling function 'c:l' I believe it's caused by the use of spring framework in the application. – Anto Jun 08 '16 at 13:55
  • Isn't label only for I18N? Stupid to repeat some value in x prop files if you make I18N application. – chillworld Jun 08 '16 at 20:24
  • @Anto I unfortunately cannot check this because I don't have an suitable testproject. – flo Jun 08 '16 at 21:48
  • @chillwold Usually it's i18n, yes, and I would declare the location elsewhere (VM or library property (https://www.zkoss.org/wiki/ZK_Configuration_Reference/zk.xml/The_library-property_Element)). But you don't have to declare a label for each lang when you have it in the parent properties file (https://www.zkoss.org/wiki/ZK_Developer's_Reference/Internationalization/Labels#Internationalization_Labels). If the key is not found in your language specific properties file (dev-common_en.properties, dev-common_es.properties, ...) there is a default fallback to the root file (dev-common.properties). – flo Jun 08 '16 at 22:03
  • If it was me, I create util class for getting props. I18N files are mostly in the war, while this url can change depending environment. So an external prop should be better. But if the link is always the same, it's the quickest solution. – chillworld Jun 09 '16 at 05:47
  • It's not for I18N, I just need to use a property to locate a specific js library that resides in an external server – Anto Jun 09 '16 at 08:36
  • @Anto You could use properties files anyway - they are not exclusively for i18n. But as chillword said, this is a compiletime setting then and cannot (easily) be modified. You should consider using environmental specific configuration options (eg something provided by the servlet container) or write/include a suitable configuration handling, allowing you to set the library's path at deploy-/runtime, depending on the server your site is running on. This way, you may not need to recompile/redeploy your application if the external server changes or similar things happen. – flo Jun 09 '16 at 09:03