Use ZK JSP Tags instead of ZK Filter"

From Documentation
m (use syntaxhighlight (via JWB))
Line 6: Line 6:
 
If some part of UI is made of HTML tags (such as header and banner), you could use JSP as the main page, implement the parts with dynamic content in ZUL, and then put them together with <jsp:include>. For example,
 
If some part of UI is made of HTML tags (such as header and banner), you could use JSP as the main page, implement the parts with dynamic content in ZUL, and then put them together with <jsp:include>. For example,
  
<syntax lang="xml">
+
<syntaxhighlight line lang="xml">
 
<%-- main.jsp --%>
 
<%-- main.jsp --%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Line 21: Line 21:
 
  </body>
 
  </body>
 
</head>
 
</head>
</syntax>
+
</syntaxhighlight>
  
 
=Use ZK components directly in a JSP page with ZK JSP tags=
 
=Use ZK components directly in a JSP page with ZK JSP tags=
Line 27: Line 27:
 
If you prefer to use ZK components directly in a JSP page, you could use [http://www.zkoss.org/product/zkjsp ZK JSP tags]. For example,
 
If you prefer to use ZK components directly in a JSP page, you could use [http://www.zkoss.org/product/zkjsp ZK JSP tags]. For example,
  
<syntax lang="xml" >
+
<syntaxhighlight line lang="xml" >
 
<%-- another.jsp --%>
 
<%-- another.jsp --%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
Line 50: Line 50:
 
</body>
 
</body>
 
</head>
 
</head>
</syntax>
+
</syntaxhighlight>
  
 
where <code>z:page</code> declares a ZK page and then ZK tags can be used inside it.
 
where <code>z:page</code> declares a ZK page and then ZK tags can be used inside it.
Line 56: Line 56:
 
The above example is equivalent to the following code snippet, if a ZUL page is used,
 
The above example is equivalent to the following code snippet, if a ZUL page is used,
  
<syntax lang="xml" >
+
<syntaxhighlight line lang="xml" >
 
<!-- another.zul -->
 
<!-- another.zul -->
 
<?page complete="true"?>
 
<?page complete="true"?>
Line 71: Line 71:
 
     </n:tr>
 
     </n:tr>
 
</n:table>
 
</n:table>
</syntax>
+
</syntaxhighlight>
  
 
where <code>&lt;?page complete="true"?&gt;</code> declares that this page is a ''complete'' page, i.e., it will provide HTML's html, head and body tags as shown above.
 
where <code>&lt;?page complete="true"?&gt;</code> declares that this page is a ''complete'' page, i.e., it will provide HTML's html, head and body tags as shown above.

Revision as of 09:02, 24 June 2021


DocumentationZK Developer's ReferencePerformance TipsUse ZK JSP Tags instead of ZK Filter
Use ZK JSP Tags instead of ZK Filter


The ZK filter actually maps each HTML tag to the corresponding XHTML components. As described in the previous section, it consumes more memory than necessary since ZK has to maintain the states of all ZK components (including XUL and XHTML components).

Include ZUL pages in a JSP page

If some part of UI is made of HTML tags (such as header and banner), you could use JSP as the main page, implement the parts with dynamic content in ZUL, and then put them together with <jsp:include>. For example,

 1 <%-- main.jsp --%>
 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 3 <html xmlns="http://www.w3.org/1999/xhtml">
 4  <head>
 5  </head>
 6  <body>
 7    <%-- the static part such as header --%>
 8    <div>any content you like</div>
 9 
10    <%-- include the dynamic part --%>
11    <jsp:include page="foo.zul"/>
12 ...
13  </body>
14 </head>

Use ZK components directly in a JSP page with ZK JSP tags

If you prefer to use ZK components directly in a JSP page, you could use ZK JSP tags. For example,

 1 <%-- another.jsp --%>
 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 3  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4 <%@ taglib uri="http://www.zkoss.org/jsp/zul" prefix="z" %>
 5 
 6 <html xmlns="http://www.w3.org/1999/xhtml">
 7  <head>
 8     <z:zkhead />
 9  </head>
10  <body>
11   <%-- any JSP content --%>
12  
13 <z:page>
14     <table>
15         <tr>
16             <td>Name</td>
17             <td><z:textbox/></td>
18         </tr>
19     </table>
20 </z:page>
21 </body>
22 </head>

where z:page declares a ZK page and then ZK tags can be used inside it.

The above example is equivalent to the following code snippet, if a ZUL page is used,

 1 <!-- another.zul -->
 2 <?page complete="true"?>
 3 <n:html xmlns="http://www.w3.org/1999/xhtml" xmlns:n="http://www.zkoss.org/2005/zk/native">
 4  <n:head>
 5  </n:head>
 6  <n:body>
 7   <!-- any HTML content -->
 8 
 9 <n:table>
10     <n:tr>
11         <n:td>Name</n:td>
12         <n:td><textbox/></n:td>
13     </n:tr>
14 </n:table>

where <?page complete="true"?> declares that this page is a complete page, i.e., it will provide HTML's html, head and body tags as shown above.

Version History

Last Update : 2021/06/24


Version Date Content
     



Last Update : 2021/06/24

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