zscript"

From Documentation
Line 35: Line 35:
 
Note: the file should contain the source codes in the selected scripting language. The encoding must be UTF-8. Don't specify a class file (aka. byte codes).
 
Note: the file should contain the source codes in the selected scripting language. The encoding must be UTF-8. Don't specify a class file (aka. byte codes).
  
Like other URL and URI, it has several characteristics as follows.
+
Like other URL and URI, it has several characteristics as follows:
  
 
# It is relative to the servlet context path (aka., the <tt>getContextPath</tt> method from the ''javax.servlet.http.HttpServletRequest'' interface). In other words, ZK will prefix it with the servlet context automatically.
 
# It is relative to the servlet context path (aka., the <tt>getContextPath</tt> method from the ''javax.servlet.http.HttpServletRequest'' interface). In other words, ZK will prefix it with the servlet context automatically.

Revision as of 04:37, 1 August 2011

Syntax:

<zscript [language="Java|JavaScript|Ruby|Groovy"]>Scripting codes</zscript>
<zscript src="a_uri" [language="Java|JavaScript|Ruby|Groovy"]/>

It defines a piece of scripting codes that will be interpreted when the page is evaluated. The language of the scripting codes is, by default, Java. You can select a different language with the use of language attribute[1].

The zscript element has two formats as shown above. The first format is used to embed the scripting codes directly in the page. The second format is used to reference an external file that contains the scripting codes.

 <zscript>
 alert("Hi");
 </zscript>
 <zscript src="/codes/my.bs"/>

Like other ZK elements, it is not a component but a special XML element.

For introductory of zscript, please refer to ZK Developer's Reference.


  1. Furthermore, you can use the page directive to change the default scripting language other than Java.

src

[Optional][Default: none]

Specifies the URI of the file containing the scripting codes. If specified, the scripting codes will be loaded as if they are embedded directly.

Note: the file should contain the source codes in the selected scripting language. The encoding must be UTF-8. Don't specify a class file (aka. byte codes).

Like other URL and URI, it has several characteristics as follows:

  1. It is relative to the servlet context path (aka., the getContextPath method from the javax.servlet.http.HttpServletRequest interface). In other words, ZK will prefix it with the servlet context automatically.
  2. It resolves "~" to other Web application (aka., different ServletContext). Notice that Web server administrator might disable Web applications from peeking other's content[1].
  3. It accepts "*" for loading browser and Locale dependent style sheet.

The algorithm to resolve "*" is as follows.

  • If there is one "*" is specified in an URL or URI such as /my*.css, then "*" will be replaced with a proper Locale depending on the preferences of user's browser.For example, user's preferences is de_DE, then ZK searches /my_de_DE.css, /my_de.css, and /my.css one-by-one from your Web site, until any of them is found. If none of them is found, /my.css is still used.
  • If two or more "*" are specified in an URL or URI such as "/my*/lang*.css", then the first "*" will be replaced with "ie" for Internet Explorer and "moz" for other browsers[2]. If the last "*" will be replaced with a proper Locale as described above.
  • All other "*" are ignored.


Notes

  1. Refer to the getContext meth from the javax.servlet.ServletContext interface.
  2. In the future editions, we will use different codes for browsers other than IE and FF.

language

[Optional][Default: the page's default scripting language][Allowed Values: Java | JavaScript | Ruby | Groovy]

It specifies the scripting language which the scripting codes are written in.

deferred

[Optional][Default: false]

Specifies whether to defer the evaluation of this element until the first non-deferred zscript codes of the same language has to be evaluated. It is used to defer the loading of the interpreter and then speed up the loading of a ZUML page. For example, if all zscript elements are deferred, they are evaluated only when the first event listened by a handler implemented in zscript is received.

For instance, in the following example, the interpreter is loaded and the zscript element is evaluated, only when the button is clicked:

<syntax lang="xml" > <window id="w">

   <zscript deferred="true">
    void addMore() {
        new Label("More").setParent(w);
    }
   </zscript>
   <button label="Add" onClick="addMore()"/>

</window> </syntax>

if

[Optional][Default: true]

Specifies the condition to evaluate this element. This element is ignored if the value specified to this attribute is evaluated to false.

unless

[Optional][Default: false]


Specifies the condition not to evaluate this element. This element is ignored if the value specified to this attribute is evaluated to true.

Version History

Version Date Content
     



Last Update : 2011/08/01

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.