Make Your Component as a JSP Tag"

From Documentation
m (Created page with '{{ZKJSPTagsEssentialsPageHeader}} =Version History= {{LastUpdated}} {| border='1px' | width="100%" ! Version !! Date !! Content |- |   |   |   |} {{ZKJSPTagsEssen…')
 
Line 1: Line 1:
 
{{ZKJSPTagsEssentialsPageHeader}}
 
{{ZKJSPTagsEssentialsPageHeader}}
 +
 +
ZK JSP Tags support all [[ZK Component Reference|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:
 +
<source lang="java">
 +
public class FooTag extends org.zkoss.jsp.zul.impl.BranchTag {
 +
    protected String getJspTagName(){
 +
        return "foo";
 +
    }
 +
}
 +
</source>
 +
 +
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]].
 +
 +
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:
 +
 +
<source lang="xml">
 +
<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>use</name>
 +
        <required>false</required>
 +
        <rtexprvalue>true</rtexprvalue>
 +
    </attribute>
 +
    <attribute>
 +
        <name>forward</name>
 +
        <required>false</required>
 +
        <rtexprvalue>true</rtexprvalue>
 +
    </attribute>
 +
</tag>
 +
</source>
 +
 +
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 <tt>if</tt>, <tt>unless</tt>, <tt>use</tt>, and <code>forward</code>.
 +
 +
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=
 
=Version History=

Revision as of 05:07, 26 November 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 [[ZUML Reference/ZUML/Languages/ZUL|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>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, 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/11/26


Version Date Content
     


Last Update : 2010/11/26

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