Annotate ZUML Pages"
Maya001122 (talk | contribs) m (Created page with '{{ZKDevelopersGuidePageHeader}} Annotations can be applied to declarations of components and properties in ZUML pages. There are two way to annotate them: the classic way and th…') |
m (correct highlight (via JWB)) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ZKDevelopersGuidePageHeader}} | {{ZKDevelopersGuidePageHeader}} | ||
+ | |||
+ | {{Old Version | ||
+ | |url=http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/Annotations/Annotate_in_ZUML | ||
+ | |}} | ||
Annotations can be applied to declarations of components and properties in ZUML pages. There are two way to annotate them: the classic way and the simple way. Which one to use depends on your favorite. You can mix them in the same page if you like. | Annotations can be applied to declarations of components and properties in ZUML pages. There are two way to annotate them: the classic way and the simple way. Which one to use depends on your favorite. You can mix them in the same page if you like. | ||
+ | === The Simple Way to Annotate the Property Declarations === | ||
+ | In addition to annotating with the special XML namespace as described above, there is a simple way to annotate properties: specify a value with an annotation expression for the property to annotate, as show below. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <listitem label="@{bind(datasource='author',selected)}"/> | ||
+ | </source> | ||
+ | |||
+ | The format of the annotation expression is <code>@{''annot-name''(''attr-name1''=''attr-value1, attr-name2=attr-value2'')}</code>. In other words, if the value of the property is an annotation expression, it is considered as the annotation for the corresponding property, rather than its value. In the above example, an annotation called <code>bind</code> is annotated to the <code>label</code> property. Thus, it is equivalent to | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <listitem a:bind=" datasource='author',selected" label=""/> | ||
+ | </source> | ||
+ | |||
+ | If the annotation name is not specified, the name is assumed to be <code>default</code>. For example, the following code snippet annotates the <code>label</code> property with an annotation named <code>default</code>, and the annotation has one attribute whose name and value are <code>value</code> and <code>selected.name</code>, respectively. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <listitem label="@{selected.name}"/> | ||
+ | </source> | ||
+ | |||
+ | In other words, it is equivalent to the following code snippet. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <listitem label="@{default(value='selected.name')}"/> | ||
+ | </source> | ||
+ | |||
+ | Note: you can annotate the same property with multiple annotations, as shown below. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <listitem label="@{ann1(selected.name) ann2(attr2a='attr2a',attr2b)}"/> | ||
+ | </source> | ||
+ | |||
+ | === The Simple Way to Annotate the Component Declarations === | ||
+ | Similarly, you can annotate a component by specifying the annotation expression to a specific attribute called <code>self</code> as shown below. | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <listitem self="@{bind(each=person)}"/> | ||
+ | </source> | ||
+ | |||
+ | where <code>self</code> is a keyword to denote the annotation is used to annotate the component declaration, rather than any property. In other words, it is equivalent to | ||
+ | |||
+ | <source lang="xml" > | ||
+ | <a:bind each="person"/> | ||
+ | <listitem/> | ||
+ | </source> | ||
{{ ZKDevelopersGuidePageFooter}} | {{ ZKDevelopersGuidePageFooter}} |
Latest revision as of 10:35, 19 January 2022
This documentation is for an older version of ZK. For the latest one, please click here.
This documentation is for an older version of ZK. For the latest one, please click here.
Annotations can be applied to declarations of components and properties in ZUML pages. There are two way to annotate them: the classic way and the simple way. Which one to use depends on your favorite. You can mix them in the same page if you like.
The Simple Way to Annotate the Property Declarations
In addition to annotating with the special XML namespace as described above, there is a simple way to annotate properties: specify a value with an annotation expression for the property to annotate, as show below.
<listitem label="@{bind(datasource='author',selected)}"/>
The format of the annotation expression is @{annot-name(attr-name1=attr-value1, attr-name2=attr-value2)}
. In other words, if the value of the property is an annotation expression, it is considered as the annotation for the corresponding property, rather than its value. In the above example, an annotation called bind
is annotated to the label
property. Thus, it is equivalent to
<listitem a:bind=" datasource='author',selected" label=""/>
If the annotation name is not specified, the name is assumed to be default
. For example, the following code snippet annotates the label
property with an annotation named default
, and the annotation has one attribute whose name and value are value
and selected.name
, respectively.
<listitem label="@{selected.name}"/>
In other words, it is equivalent to the following code snippet.
<listitem label="@{default(value='selected.name')}"/>
Note: you can annotate the same property with multiple annotations, as shown below.
<listitem label="@{ann1(selected.name) ann2(attr2a='attr2a',attr2b)}"/>
The Simple Way to Annotate the Component Declarations
Similarly, you can annotate a component by specifying the annotation expression to a specific attribute called self
as shown below.
<listitem self="@{bind(each=person)}"/>
where self
is a keyword to denote the annotation is used to annotate the component declaration, rather than any property. In other words, it is equivalent to
<a:bind each="person"/>
<listitem/>