Custom Taglib"

From Documentation
Line 2: Line 2:
 
=The Syntax of Taglib Document=
 
=The Syntax of Taglib Document=
  
The syntax of a Taglib document is the same as JSP's taglib (aka., TLD), so you could use JSP's TLD files directly. However, ZK only recognize the function elements. All others are ignored.
+
The syntax of a Taglib document is the same as JSP's taglib (aka., TLD), so you could use JSP's TLD files directly. However, ZK only recognizes the function elements. All others are ignored.
  
 
Here is an example:
 
Here is an example:
Line 34: Line 34:
 
*The root element must be called <code>taglib</code>
 
*The root element must be called <code>taglib</code>
 
*Each function declaration must be called <code>function</code>. It requires three sub-elements: <code>name</code>, <code>function-class</code> and <code>function-signature</code>. The <code>description</code> element is optional (for documentation only).
 
*Each function declaration must be called <code>function</code>. It requires three sub-elements: <code>name</code>, <code>function-class</code> and <code>function-signature</code>. The <code>description</code> element is optional (for documentation only).
 +
 +
In additions, you could import all public static methods with the element called <code>import</code>, and the name of EL function will be the same as the method name. For example,
 +
 +
<source lang="xml">
 +
<import>
 +
<import-name>Labels</import-name>
 +
<import-class>org.zkoss.util.resource.Labels</import-class>
 +
</import>
 +
</source>
  
 
=Configure Tag Documents as Built-in=
 
=Configure Tag Documents as Built-in=

Revision as of 10:08, 15 November 2010

The Syntax of Taglib Document

The syntax of a Taglib document is the same as JSP's taglib (aka., TLD), so you could use JSP's TLD files directly. However, ZK only recognizes the function elements. All others are ignored.

Here is an example:

<taglib>
    <function>
        <name>browser</name>
        <function-class>org.zkoss.web.fn.ServletFns</function-class>
        <function-signature>
    boolean isBrowser(java.lang.String)
        </function-signature>
        <description>
    Whether the current request is coming from the browser of the specified
    type.
        </description>
    </function>
    <function>
        <name>l</name>
        <function-class>org.zkoss.xel.fn.CommonFns</function-class>
        <function-signature>java.lang.String getLabel(java.lang.String)</function-signature>
        <description>
        Returns the label of the specified key.
        </description>
    </function>
</taglib>

where

  • The root element must be called taglib
  • Each function declaration must be called function. It requires three sub-elements: name, function-class and function-signature. The description element is optional (for documentation only).

In additions, you could import all public static methods with the element called import, and the name of EL function will be the same as the method name. For example,

<import>
	<import-name>Labels</import-name>
	<import-class>org.zkoss.util.resource.Labels</import-class>
</import>

Configure Tag Documents as Built-in

Version History

Last Update : 2010/11/15

Version Date Content
     



Last Update : 2010/11/15

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