The native Namespace

From Documentation


The native Namespace


Overview

With the native namespace, a XML element in a ZUML document will be interpreted as a native tag that shall be sent to the browser directly, rather than becoming a ZK component.

For example,

 <n:ul xmlns:n="native">
     <n:li>
     <textbox/>
     </n:li>
     <n:li>
     <textbox/>
     </n:li>
 </n:ul>

will attach the following HTML tags to the browser's DOM tree:

 <ul>
     <li>
     <input id="z_a3_2"/>
     </li>
     <li>
     <input id="z_a3_5"/>
     </li>
 </ul

where <input> is the HTML tag(s) generated by the textbox component. Unlike textbox in the example above, ZK Loader doesn't really create a component for each of ul and li.[1] Rather, they are sent to the client directly. Of course, they must be recognizable by the client. For a HTML browser, they must be the valid HTML tags.


  1. ZK ZK actually creates a special component to represent as many XML elements with the native namespace as possible.

Dynamic Update

The XML elements associated with the native namespace will be considered as tags that the client accepts, and they are sent directly to the client to display. They are not ZK components, and they don't have the counterpart (widget) at the client either. The advantage is the better performance in term of both memory and processing time.

However, the disadvantage is you cannot access or change them (neither component nor widget) dynamically. For example, the following code snippet is incorrect, since there is no component called x.

 <n:ul id="x" xmlns:n="native"/>
 <button label="add" onClick="new Li().setParent(x)"/> <!-- Failed since x is not available at the server -->

If you want to change them dynamically, you could:

  1. Use client-side code to modify the browser's DOM tree at the client. Notice that, since ZK doesn't create the widget at the client too, you have to manipulate the DOM tree directly.
  2. Use the html component if you won't mix ZUL with HTML tags.
  3. Use the components from the XHTML component set as described in the following section.

For example, we could use jQuery to modify the DOM tree as follows:

<zk xmlns:n="native" xmlns:w="client">
	<n:input id="inp"/>
	<button label="change" w:onClick="jq('#inp')[0].value = 'clicked'"/>
</zk>

The rule of thumb is to use the native namespace if possible. If you need to change the content dynamically, you might consider the html component first. If still not applicable, use the XHTML component set.

Relation With Other Components

Though no component is associated with the element specified with the native namespace, you still could manipulate its parent, such as invalidate and move. For example, the following works correctly.

<window border="normal" title="Redraw">
  <n:ul xmlns:n="native">
     <n:li>ZK is simply best</n:li>
  </n:ul xmlns:n="native">
  <button label="Redraw" onClick="self.getParent().invalidate()"/><!-- OK to invalidate a component -->
</window>

As shown, it is OK to invalidate a component even if it has some native tags.

Also notice that, though the native HTML tags will be generated for the native namespace, ZK Loader actually creates a component to represent as many as these native HTML tags. Thus, if you invoke Component.getPreviousSibling() of the button above, it will return this component. However, don't access it since the real class/implementation of the component depends on the version you use and might be changed in the future.

Output Tags with Another Namespace

If the HTML tag you want to output requires a XML namespace (such as XAML), you can use the following format to specify the URI of the XML namespace you want to output:

<element xmlns="native:URI-of-another-namespace">

For example, if you want to output the XAML tags directly to the client, you can specify XAML's XML namespace as follows.

<div>
	<Canvas xmlns="native:http://schemas.microsoft.com/client/2007">
	  <TextBlock>Hello World!</TextBlock>
	</Canvas>
</div>

Then, the result DOM structure will be similar to the following[1]:

<div id="zk_uuid">
     <canvas xmlns="http://schemas.microsoft.com/client/2007">
          <textblock>Hello World!</textblock>
     </canvas>
</div>

  1. The real DOM structure of a component (div in this example) depends on its implementation. Here is only a simplified version.

Version History

Last Update : 2010/11/11

Version Date Content
     



Last Update : 2010/11/11

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