zscript"
Maya001122 (talk | contribs) (Created page with '== The zscript Element == <source lang="xml" > <zscript [language="Java|JavaScript|Ruby|Groovy"]>''Scripting codes''</zscript> <zscript src="''uri''" [language="Java|JavaScrip…') |
m (correct highlight (via JWB)) |
||
(22 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{ZUMLReferencePageHeader}} | |
− | + | __TOC__ | |
− | <zscript [language="Java|JavaScript|Ruby|Groovy"]>''Scripting codes''</zscript> | + | |
− | <zscript src="'' | + | '''Syntax:''' |
− | + | <zscript [language="'''Java'''|JavaScript|Ruby|Groovy|Python"] [if="''if-condition''"] [unless="''unless-condition''"]>''Scripting codes''</zscript> | |
+ | <zscript src="''a_uri''" [language="'''Java'''|JavaScript|Ruby|Groovy"] [if="''if-condition''"] [unless="''unless-condition''"]/> | ||
− | 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 | + | 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 <code>language</code> attribute<ref>Furthermore, you can use the page directive to change the default scripting language other than Java.</ref>. |
− | The < | + | The <code>zscript</code> 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. |
<source lang="xml" > | <source lang="xml" > | ||
Line 19: | Line 20: | ||
Like other ZK elements, it is not a component but a special XML element. | 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/UI Composing/ZUML/Scripts in ZUML|ZK Developer's Reference]]. | ||
− | + | <blockquote> | |
+ | ---- | ||
<references/> | <references/> | ||
+ | </blockquote> | ||
== src == | == src == | ||
− | + | [Optional][Default: ''none''] | |
− | [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. | 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 | + | 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 < | + | # It is relative to the servlet context path (aka., the <code>getContextPath</code> method from the ''javax.servlet.http.HttpServletRequest'' interface). In other words, ZK will prefix it with the servlet context automatically. |
− | # It resolves "~" to other Web application (aka., different ServletContext). Notice that Web server administrator might disable Web applications from peeking other's content<ref>Refer to the < | + | # It resolves "~" to other Web application (aka., different ServletContext). Notice that Web server administrator might disable the Web applications from peeking other's content<ref>Refer to the <code>getContext</code> meth from the javax.servlet.ServletContext interface.</ref>. |
# It accepts "*" for loading browser and Locale dependent style sheet. | # It accepts "*" for loading browser and Locale dependent style sheet. | ||
The algorithm to resolve "*" is as follows. | The algorithm to resolve "*" is as follows. | ||
− | * If there is one "*" | + | * If there is one "*" specified in an URL or URI such as <code>/my*.css</code>, then "*" will be replaced with a proper Locale depending on the preferences of user's browser.For example, user's preferences is <code>de_DE</code>, then ZK searches <code>/my_de_DE.css</code>, <code>/my_de.css</code>, and <code>/my.css</code> one-by-one from your Web site, until any of them is found. If none of them is found, <code>/my.css </code>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 "< | + | * If two or more "*" are specified in an URL or URI such as "/my*/lang*.css", then the first "*" will be replaced with "<code>ie</code>" for Internet Explorer and "<code>moz</code>" for other browsers<ref>In the future editions, we will use different codes for browsers other than IE and FF.</ref>. If the last "*" will be replaced with a proper Locale as described above. |
* All other "*" are ignored. | * All other "*" are ignored. | ||
Line 51: | Line 53: | ||
== language == | == language == | ||
− | + | [Optional][Default: the page's default scripting language][Allowed Values: Java | JavaScript | Ruby | Groovy | Python] | |
− | [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. | It specifies the scripting language which the scripting codes are written in. | ||
+ | |||
+ | Except Java, you have to include corresponding script engines jar files manually by yourselves before using them in this element, like: | ||
+ | |||
+ | Ruby: | ||
+ | <source lang='xml'> | ||
+ | <dependency> | ||
+ | <groupId>org.jruby</groupId> | ||
+ | <artifactId>jruby</artifactId> | ||
+ | <version>1.1.2</version> | ||
+ | </dependency> | ||
+ | </source> | ||
+ | Python: | ||
+ | <source lang='xml'> | ||
+ | <dependency> | ||
+ | <groupId>org.python</groupId> | ||
+ | <artifactId>jython</artifactId> | ||
+ | <version>2.2.1</version> | ||
+ | </dependency> | ||
+ | </source> | ||
+ | JavaScript: | ||
+ | <source lang='xml'> | ||
+ | <dependency> | ||
+ | <groupId>org.mozilla</groupId> | ||
+ | <artifactId>rhino</artifactId> | ||
+ | <version>1.7R4</version> | ||
+ | </dependency> | ||
+ | </source> | ||
+ | Groovy: | ||
+ | <source lang='xml'> | ||
+ | <dependency> | ||
+ | <groupId>org.codehaus.groovy</groupId> | ||
+ | <artifactId>groovy-all</artifactId> | ||
+ | <version>1.5.6</version> | ||
+ | </dependency> | ||
+ | </source> | ||
== deferred == | == deferred == | ||
− | + | [Optional][Default: false] | |
− | [Optional][Default: false] | + | |
− | </ | + | Specifies whether to defer the evaluation of this element until the first non-deferred <code>zscript</code> 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 <code>zscript</code> elements are deferred, they are evaluated only when the first event listened by a handler implemented in <code>zscript</code> is received. |
− | + | For instance, in the following example, the interpreter is loaded and the zscript element is evaluated, only when the button is clicked: | |
− | + | <syntaxhighlight line lang="xml" > | |
+ | <window id="w"> | ||
+ | <zscript deferred="true"> | ||
+ | void addMore() { | ||
+ | new Label("More").setParent(w); | ||
+ | } | ||
+ | </zscript> | ||
+ | <button label="Add" onClick="addMore()"/> | ||
+ | </window> | ||
+ | </syntaxhighlight> | ||
== if == | == if == | ||
− | + | [Optional][Default: true] | |
− | [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. | Specifies the condition to evaluate this element. This element is ignored if the value specified to this attribute is evaluated to false. | ||
Line 77: | Line 119: | ||
== unless == | == unless == | ||
− | + | [Optional][Default: false] | |
− | [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. | 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== | ||
+ | |||
+ | {| border='1px' | width="100%" | ||
+ | ! Version !! Date !! Content | ||
+ | |- | ||
+ | | | ||
+ | | | ||
+ | | | ||
+ | |} | ||
+ | |||
+ | {{ZUMLReferencePageFooter}} |
Latest revision as of 13:27, 19 January 2022
Syntax:
<zscript [language="Java|JavaScript|Ruby|Groovy|Python"] [if="if-condition"] [unless="unless-condition"]>Scripting codes</zscript> <zscript src="a_uri" [language="Java|JavaScript|Ruby|Groovy"] [if="if-condition"] [unless="unless-condition"]/>
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.
- ↑ 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:
- 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. - It resolves "~" to other Web application (aka., different ServletContext). Notice that Web server administrator might disable the Web applications from peeking other's content[1].
- It accepts "*" for loading browser and Locale dependent style sheet.
The algorithm to resolve "*" is as follows.
- If there is one "*" 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 isde_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
language
[Optional][Default: the page's default scripting language][Allowed Values: Java | JavaScript | Ruby | Groovy | Python]
It specifies the scripting language which the scripting codes are written in.
Except Java, you have to include corresponding script engines jar files manually by yourselves before using them in this element, like:
Ruby:
<dependency>
<groupId>org.jruby</groupId>
<artifactId>jruby</artifactId>
<version>1.1.2</version>
</dependency>
Python:
<dependency>
<groupId>org.python</groupId>
<artifactId>jython</artifactId>
<version>2.2.1</version>
</dependency>
JavaScript:
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7R4</version>
</dependency>
Groovy:
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.5.6</version>
</dependency>
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:
1 <window id="w">
2 <zscript deferred="true">
3 void addMore() {
4 new Label("More").setParent(w);
5 }
6 </zscript>
7 <button label="Add" onClick="addMore()"/>
8 </window>
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 |
---|---|---|