Mix With Another Markup Language

From Documentation
Revision as of 10:36, 19 January 2022 by Hawk (talk | contribs) (correct highlight (via JWB))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Stop.png This documentation is for an older version of ZK. For the latest one, please click here.


To mix with another markup language, you have to use xmlns to specify the correct namespace.

 <window xmlns:h="http://www.w3.org/1999/xhtml">
     <h:div>
         <button/>
     </h:div>
 </window>

For the XHTML components, the onClick and onChange attributes are conflicts with ZK's attributes. To resolve, you have to use the reserved namespace, http://www.zkoss.org/2005/zk, as follows.

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:x="[http://www.potix.com/2005/zul http://www.zkoss.org/2005/zul]"
      xmlns:zk="http://www.zkoss.org/2005/zk">
	<head>
		<title>ZHTML Demo</title>
	</head>
	<body>
		<script type="text/javascript">
		function woo() { //running at the browser
		}
		</script>
		<zk:zscript>
		void addItem() { //running at the server
		}
		</zk:zscript>
		<x:window title="HTML App">
			<input type="button" value="Add Item"
			onClick="woo()" zk:onClick="addItem()"/>
		</x:window>
	</body>
</html>


In this example, the onClick attribute is a ZHTML's attribute to specify JavaScript codes to run at the browser. On the other hand, the zk:onClick is a reserved attribute for specify a ZK event handler.

Notice that the namespace prefix, zk, is optional for the zscript element, because ZHTML has no such element and ZK has enough information to determine it.

Also notice that you have to specify the XML namespace for the window component, because it is from a different component set.

Auto-completion with Schema

Many IDEs, such Eclipse, supports auto-completion if XML schema is specified as follows.

 <window xmlns="http://www.zkoss.org/2005/zul"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.zkoss.org/2005/zul http://www.zkoss.org/2005/zul/zul.xsd">

In addition to downloading from http://www.zkoss.org/2005/zul/zul.xsd, you can find zul.xsd under the dist/xsd directory in the ZK binary distribution.




Last Update : 2022/01/19

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