Templating"

From Documentation
m
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
{{ZKDevelopersReferencePageHeader}}
 
{{ZKDevelopersReferencePageHeader}}
  
Templating is a technique that allows developers to define UI fragments, and how to assemble them into a complete UI at runtime. With ZK, it can be done by use of annotations and composer (or initators, <javadoc type="interface">org.zkoss.zk.ui.utilInitiator</javadoc>).
+
Templating is a technique that allows developers to define UI fragments, and how to assemble them into a complete UI at runtime. With ZK, it can be done by the use of annotations and composers (or initators, <javadoc type="interface">org.zkoss.zk.ui.utilInitiator</javadoc>).
  
The basic idea is to specify the name of a fragment as [[ZK Developer's Reference/Annotations|annotations]] in a ZUML document that shall represent a complete UI, and a composer that is capable to parse annotations and replace them with the fragment. For example,
+
In general, templating can be done by specifying the name of a fragment as [[ZK Developer's Reference/Annotations|annotations]] in a ZUML document that shall represent a complete UI, and a composer that is capable to parse annotations and replace them with the fragment. For example,
  
 
<source lang="xml">
 
<source lang="xml">
<div apply="foo.MyTemplateManager">
+
<div apply="foo.MyTemplateManager"><!-- your template manager -->
     <include src="@{header}"/><!-- you could use any component as long as your manager knows how to handle it -->
+
     <include src="@header()"/><!-- you could use any component as long as your manager knows how to handle it -->
     <include src="@{content}"/>
+
     <include src="@content()"/>
     <include src="@{footer}"/>
+
     <include src="@footer()"/>
 
</div>
 
</div>
 
</source>
 
</source>
  
Here is the implementation that ZK supports by default. You could implement your own, if it does not fulfill your requirement.
+
Here is a list of the implementations that ZK supports by default. You could implement your own, if it does not fulfill your requirement. If the templating is stateful and dynamical, you might consider [http://www.zkoss.org/product/zkspring.dsp ZK Spring] for using Spring Web Flow instead.
  
 
{{ZKDevelopersReferenceHeadingToc}}
 
{{ZKDevelopersReferenceHeadingToc}}
 
{{ZKDevelopersReferencePageFooter}}
 
{{ZKDevelopersReferencePageFooter}}

Latest revision as of 09:50, 27 April 2012

Templating is a technique that allows developers to define UI fragments, and how to assemble them into a complete UI at runtime. With ZK, it can be done by the use of annotations and composers (or initators, Initiator).

In general, templating can be done by specifying the name of a fragment as annotations in a ZUML document that shall represent a complete UI, and a composer that is capable to parse annotations and replace them with the fragment. For example,

<div apply="foo.MyTemplateManager"><!-- your template manager -->
    <include src="@header()"/><!-- you could use any component as long as your manager knows how to handle it -->
    <include src="@content()"/>
    <include src="@footer()"/>
</div>

Here is a list of the implementations that ZK supports by default. You could implement your own, if it does not fulfill your requirement. If the templating is stateful and dynamical, you might consider ZK Spring for using Spring Web Flow instead.


Subsections:



Last Update : 2012/04/27

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