Use Native Namespace instead of XHTML Namespace"

From Documentation
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
As described in the [[ZK Developer's Reference/UI Composing/ZUML/Standard Languages/ZHTML Language|ZUML Language]] section and the [[Work with HTML Tags]] section of the '''ZUML with the XUL Component Set''' chapter, ZK creates a ZK component for each XML element specified with the XHTML namespace. In other words, ZK has to maintain their states at the server. Since the number of HTML tags are usually large, the performance will be improved dramatically if you use the Native namespace instead.
+
ZK creates a component (one of the derives of <javadoc>org.zkoss.zhtml.AbstractTag</javadoc>) for each XML element specified with the [[ZUML Reference/ZUML/Languages/XHTML|XHTML component set]]. In other words, ZK will maintain their states at the server. However, if you won't change their states dynamically (i.e., after instantiated), you could use the [[ZUML Reference/ZUML/Namespaces/Native|native namespace]] instead.
  
 
For example, the following code snippet creates five components (one <tt>table</tt>, <tt>tr</tt>, <tt>textbox</tt> and two <tt>td</tt>).
 
For example, the following code snippet creates five components (one <tt>table</tt>, <tt>tr</tt>, <tt>textbox</tt> and two <tt>td</tt>).
  
 
<syntax lang="xml" >
 
<syntax lang="xml" >
<h:table xmlns:h="http://www.w3.org/1999/xhtml">
+
<h:table xmlns:h="xhtml">
 
     <h:tr>
 
     <h:tr>
 
         <h:td>Name</h:td>
 
         <h:td>Name</h:td>
Line 16: Line 16:
 
</syntax>
 
</syntax>
  
On the other hand, the following code snippet creates two components (one special component to generate <tt>table</tt>, <tt>tr</tt> and <tt>td</tt> to the client, and one <tt>textbox</tt>).
+
On the other hand, the following code snippet won't create components for any elements specified with the native space (with prefix <code>n:</code>)<ref>In fact, it will still creates some components for the rerender purpose, such as <javadoc method="invalidate()">org.zkoss.zk.ui.Component</javadoc>. However, since they shall not be accessed, you could image there are not created at all.</ref>.
  
 
<syntax lang="xml" >
 
<syntax lang="xml" >
Line 29: Line 29:
 
</syntax>
 
</syntax>
  
Notice that <tt>table</tt>, <tt>tr</tt> and <tt>td</tt> are generated directly to the client, so they don't have no counterpart at the client. Thus, you can not change it dynamically. For example, the following code snippet is incorrect.
+
Notice that <tt>table</tt>, <tt>tr</tt> and <tt>td</tt> are generated directly to the client, so they don't have no counterpart at the client either. You can not change their states dynamically. For example, the following code snippet is incorrect.
  
 
<syntax lang="xml" >
 
<syntax lang="xml" >
Line 36: Line 36:
 
</syntax>
 
</syntax>
  
Rather, you have to use the <tt>html</tt> component or the XHTML namespace, if you want to change dynamically.
+
If you have to change them dynamically, you still have to use the [[ZUML Reference/ZUML/Languages/XHTML|XHTML component set]], or you could use <javadoc>org.zkoss.zul.Html</javadoc> alternatively, if the HTML tags won't contain any ZUL component.
  
 
=Version History=
 
=Version History=

Revision as of 09:54, 10 November 2010


DocumentationZK Developer's ReferencePerformance TipsUse Native Namespace instead of XHTML Namespace
Use Native Namespace instead of XHTML Namespace


ZK creates a component (one of the derives of AbstractTag) for each XML element specified with the XHTML component set. In other words, ZK will maintain their states at the server. However, if you won't change their states dynamically (i.e., after instantiated), you could use the native namespace instead.

For example, the following code snippet creates five components (one table, tr, textbox and two td).

<syntax lang="xml" > <h:table xmlns:h="xhtml">

   <h:tr>
       <h:td>Name</h:td>
       <h:td>
       <textbox/>
       </h:td>
   </h:tr>

</h:table> </syntax>

On the other hand, the following code snippet won't create components for any elements specified with the native space (with prefix n:)[1].

<syntax lang="xml" > <n:table xmlns:n="native">

   <n:tr>
       <n:td>Name</n:td>
       <n:td>
       <textbox/>
       </n:td>
   </n:tr>

</n:table> </syntax>

Notice that table, tr and td are generated directly to the client, so they don't have no counterpart at the client either. You can not change their states dynamically. For example, the following code snippet is incorrect.

<syntax lang="xml" > <n:ul id="x" xmlns:n="native"/> <button label="add" onClick="new Li().setParent(x)"/> </syntax>

If you have to change them dynamically, you still have to use the XHTML component set, or you could use Html alternatively, if the HTML tags won't contain any ZUL component.

Version History

Version Date Content
     



Last Update : 2010/11/10

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


  1. In fact, it will still creates some components for the rerender purpose, such as Component.invalidate(). However, since they shall not be accessed, you could image there are not created at all.