zscript"
Line 39: | Line 39: | ||
<source lang="xml"> | <source lang="xml"> | ||
<button label="alert" onClick="python:alert('Hi, Python')"/> | <button label="alert" onClick="python:alert('Hi, Python')"/> | ||
+ | </source> | ||
+ | |||
+ | = Support More Scripting Languages == | ||
+ | Currently ZK supports Java, JavaScript, Ruby, Groovy, and Python. However, it is easy to extend: | ||
+ | |||
+ | # Provide a class that implements <javadoc type="interface">org.zkoss.zk.scripting.Interpreter</javadoc>. However, it is suggested to derive from <javadoc>org.zkoss.zk.scripting.util.GenericInterpreter</javadoc> for simplicity. | ||
+ | # Declare the scripting language in either [[ZK Configuration Reference/zk.xml/The zscript-config Element|WEB-INF/zk.xml]], or <tt>zk/config.xml</tt>. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <zscript-config> | ||
+ | <language-name>SuperJava</language-name><!-- case insensitive --> | ||
+ | <interpreter-class>my.MySuperJavaInterpreter</interpreter-class> | ||
+ | </zscript-config> | ||
</source> | </source> | ||
Revision as of 10:03, 24 November 2010
The default interpreter for the zscript elements is Java (based on BeanShell). Depending on your preference, you could choose one of built-in interpreters, or implement your own interpreter.
The built-in interpreters includes: Java, Groovy, Ruby, Python, and JavaScript.
Choose Interpreter for Whole Page
To change the default interpreter for the whole page, you could use the page directive by specifying the zscriptLanguage attribute, such as
<?page zscriptLanguage="Groovy"?>
<window border="normal">
<vbox id="vb">
<label id="l" value="Hi"/>
<button label="change label" onClick="l.value='Hi, Groovy';"/>
<button label="add label" onClick="new Label('New').setParent(vb);"/>
</vbox>
<button label="alert" onClick="alert('Hi, Groovy')"/>
</window>
Choose Interpreter for zscript
You could choose an interpreter for a particular zscript element by specifying the language attribute as follows.
<zscript language="Ruby">
(Java::Label.new 'New').parent = $vb
</zscript>
Choose Interpreter for Event Handler
You could choose an interpreter for a particular event handler by prefixing it with the language name as follows.
<button label="alert" onClick="python:alert('Hi, Python')"/>
Support More Scripting Languages =
Currently ZK supports Java, JavaScript, Ruby, Groovy, and Python. However, it is easy to extend:
- Provide a class that implements Interpreter. However, it is suggested to derive from GenericInterpreter for simplicity.
- Declare the scripting language in either WEB-INF/zk.xml, or zk/config.xml.
<zscript-config>
<language-name>SuperJava</language-name><!-- case insensitive -->
<interpreter-class>my.MySuperJavaInterpreter</interpreter-class>
</zscript-config>
Version History
Last Update : 2010/11/24
Version | Date | Content |
---|---|---|