Languages
Overview
A language (LanguageDefinition) is a collection of component definitions. It is also known as a component set.
For example, Window, Button and Combobox all belong to the same language called xul/html
. It is a ZK variant of XUL (and also known as zul
).
Component designers are free to designate a component definition to any component set they prefer, as long as there is no name conflict[1].
Identify a Language
Identify by Filename's Extension
First, when a ZUML file is parsed, the language will be decided based on the extension of the filename (LanguageDefinition.getByExtension(String)). For example, the extensions associated with xul/html
are zul
and xul
. Thus, if any file whose extension is zul
or xul
, the default language used to parse it will be assumed to be the xul/html
language.
Another example: xhtml
is another language (aka., a component set). It is associated with the extensions including zhtml
, html
, html
, and xhtml
. Thus, any file whose extension matches one of them will be considered as applying the zhtml
language as default.
Notice that the association of filename's extension with a language is about how ZK Loader processes a ZUML page. To really have ZK Loader to process a file, you have to configure WEB-INF/web.xml
correctly. For example, if you want to map all XUL files to ZK Loader, you could add the following to WEB-INF/web.xml
:
<servlet-mapping>
<servlet-name>zkLoader</servlet-name>
<url-pattern>*.xul</url-pattern>
</servlet-mapping>
Identify by XML Namespace
If you map ZK Loader to a filename's extension that is not recognized, you could use XML namespaces to specify the language used to parse it. Each language is associated with a unique XML namespace that you can identify it easily in a ZUML document.
For example, you map ZK Loader to *.foo
, then you could specify the xul/html language's namespace, which is http://www.zkoss.org/2005/zul
:
<window xmlns="http://www.zkoss.org/2005/zul">
...
where the xmlns attribute declares a XML namespace to associate all element without explicit prefix, such as window in this case.
If you want to several languages in the same XML document, you could use XML namespaces to distinguish them too. For example, the xhtml language's namespace is http://www.w3.org/1999/xhtml
, and we could do as follows.
<window xmlns:h="http://www.w3.org/1999/xhtml">
<h:table>
<h:tr>
<h:td>
<button/>
</h:td>
</h:tr>
</h:table>
</window>
Notice that table, tr and td are also components though they are very simple -- a simple wrapper of HTML tags. There is a better way to generate HTML tags: the native namespace. For more information please refer to the Native Namespace section.
Identify by XML Namespace with Shortcut
To make it easy to specify a namespace, ZK Loader allows shortcut. That is, you need to only specify the last word of the namespace. For example, zul
for http://www.zkoss.org/2005/zul
, and xhtml
for http://www.w3.org/1999/xhtml. Thus, we can simply the previous example as follows.
<window xmlns:h="xhtml">
<h:span>
<h:tr>
<h:td>
<button/>
</h:td>
</h:tr>
</h:table>
</window>
Standard Languages
ZK provides three different languages (aka., component sets): xul/xhtml, xhtml and xml. The xul/xhtml and xhtml langauges can be used for any modern browser (Ajax assumed), while the zml language is used for generating XML document (non-Ajax). Developers are free to add their own language.
Language | Description |
---|---|
xul/html |
Name: xul/html File Extensions: zul, xul Namespace: http://www.zkoss.org/2005/zul Namespace shortcut: zul Device: Ajax XUL-compliant component sets. We adopt XUL for this language, if the specification is applicable. For more information, please refer to the ZUL Language section and ZK Component Reference. |
xhtml |
Name: xhtml File Extensions: zhtml, xhtml, html, htm Namespace: http://www.w3.org/1999/xhtml Namespace shortcut: xhtml Device: Ajax XHTML-compliant component sets. It is one-to-one mapping of XHTML tags to ZK components. Since they are components, you can add and remove them dynamically (and control it at the server). For more information please refer to the XHTML Namespace section or ZK Component Reference. Performance Tip: The XHTML language is designed to allow application to modify the client dynamically (at the server). If you don't need it (it is generally true), you shall use the Native namespace instead. For more information, please refer to Performance Tips. |
xml |
Name: xml File Extensions: xml Namespace: http://www.zkoss.org/2007/xml Namespace shortcut: xml Device: XML Available only ZK EE XML component sets. It is used to generate (static) XML document. For more information please refer to the XML section. |
- ↑ For more information please refer to ZK Component Development Essentials
Version History
Last Update : 2010/11/5
Version | Date | Content |
---|---|---|