Make Your Component as a JSP Tag"

From Documentation
m
Line 14: Line 14:
 
ZK will invoke getJspTagName() method to get the  tag name. The name will be used to look for the component definition from [[ZUML Reference/ZUML/Languages/ZUL|the ZUL component set]].
 
ZK will invoke getJspTagName() method to get the  tag name. The name will be used to look for the component definition from [[ZUML Reference/ZUML/Languages/ZUL|the ZUL component set]].
  
Notice that the name must be the same you specify in your [[ZK Developer's Reference/Language Definition|component definition]].
+
Notice that the name must be the same you specify in your [[ZK Client-side Reference/Language Definition|component definition]].
  
 
2. Follow the JSP specification to declare your JSP tag in [http://download.oracle.com/javaee/1.4/tutorial/doc/JSPTags6.html TLD]. For example:
 
2. Follow the JSP specification to declare your JSP tag in [http://download.oracle.com/javaee/1.4/tutorial/doc/JSPTags6.html TLD]. For example:

Revision as of 01:58, 3 December 2010


Make Your Component as a JSP Tag



ZK JSP Tags support all ZUL components. That is, every ZUL component has a corresponding JSP tag. If you want to make your own ZK component as a JSP tag, you could do as follows:

1. Create a Java class like this:

public class FooTag extends org.zkoss.jsp.zul.impl.BranchTag {
    protected String getJspTagName(){
        return "foo";
    }
}

ZK will invoke getJspTagName() method to get the tag name. The name will be used to look for the component definition from the ZUL component set.

Notice that the name must be the same you specify in your component definition.

2. Follow the JSP specification to declare your JSP tag in TLD. For example:

<tag>
<name>foo</name>
    <tag-class>com.foo.FooTag</tag-class>
    <body-content>scriptless</body-content>
    <dynamic-attribute>true</dynamic-attribute>
    <attribute> 
        <name>if</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute> 
        <name>unless</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute> 
        <name>apply</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute> 
        <name>use</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute> 
        <name>forward</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
    </attribute>
</tag>

Although the dynamic attribute can be set true and JSP will accept all kinds of attributes, you still need to add the special attributes in your JSP tag definition. The special attributes include if, unless, apply, use, and forward.

3. Use TLD in JSP document with <%@ taglib%> After the tag definition is done, you could use it in JSP document just like any other JSP tags. Of course, you have to specify TLD first.


Version History

Last Update : 2010/12/03


Version Date Content
     


Last Update : 2010/12/03

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