Annotate in ZUML"

From Documentation
Line 3: Line 3:
  
 
= Annotate Properties =
 
= Annotate Properties =
To annotate a property, you could specify a value with an annotation expression for the property to annotate. The format of an annotation expression is <tt>@{''annot-name''(''attr-name1''=''attr-value1, attr-name2=attr-value2'')}</tt>.  For example,
+
To annotate a property, you could specify an annotation expression as the value for the property to annotate. The format of an annotation expression is <tt>@{''annot-name''(''attr-name1''=''attr-value1, attr-name2=attr-value2'')}</tt>.  For example,
  
 
<source lang="xml" >
 
<source lang="xml" >
<listitem label="@{bind(datasource='author',selected)}"/>
+
<listitem label="@{bind(datasource='author',value='selected')}"/>
 
</source>
 
</source>
  
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 <tt>bind</tt> is annotated to the <tt>label</tt> property, and the <tt>bind</tt> property has two attributes: <tt>datasource</tt> and <tt>selected</tt>.
+
In other words, if the value of the property is an annotation expression, it is considered as an annotation for the property, rather than a value be be assigned.
  
If the annotation name is not specified, the name is assumed to be <tt>default</tt>. For example, the following code snippet annotates the <tt>label</tt> property with an annotation named <tt>default</tt>, and the annotation has one attribute whose name and value are <tt>value</tt> and <tt>selected.name</tt>, respectively.
+
An annotation starts with a name and a map of attributes. Each attribute is a name-value pair. For example, the above code annotates an annotation called <tt>bind</tt> to the <tt>label</tt> property, and the <tt>bind</tt> property has two attributes: <tt>datasource</tt> and <tt>value</tt>.
 +
 
 +
If the annotation name is not specified, the name is assumed to be <tt>default</tt>. For example, the following two statements are equivalent:
 +
 
 +
<source lang="xml">
 +
<listitem label="@{datasource='foo'}"/>
 +
<listitem label="@{default(datasource='foo')}"/>
 +
</source>
 +
 
 +
If the attribute name is not specified, it is assumed to be <tt>value</tt>. For example, the following two statements are equivalent:
 +
 
 +
<source lang="xml">
 +
<listitem label="@{bind(foo)}"/>
 +
<listitem label="@{bind(value='foo')}"/>
 +
</source>
 +
 
 +
Here is a more complex example.
  
 
<source lang="xml" >
 
<source lang="xml" >
Line 17: Line 33:
 
</source>
 
</source>
  
In other words, it is equivalent to the following code snippet.
+
where it annotates the <tt>label</tt> property with an annotation named <tt>default</tt>, and the annotation has one attribute whose name and value are <tt>value</tt> and <tt>selected.name</tt>, respectively. In other words, it is equivalent to the following code snippet.
  
 
<source lang="xml" >
 
<source lang="xml" >

Revision as of 08:15, 17 November 2010


Annotate in ZUML


Annotations can be applied to declarations of components and properties in ZUML pages.

Annotate Properties

To annotate a property, you could specify an annotation expression as the value for the property to annotate. The format of an annotation expression is @{annot-name(attr-name1=attr-value1, attr-name2=attr-value2)}. For example,

<listitem label="@{bind(datasource='author',value='selected')}"/>

In other words, if the value of the property is an annotation expression, it is considered as an annotation for the property, rather than a value be be assigned.

An annotation starts with a name and a map of attributes. Each attribute is a name-value pair. For example, the above code annotates an annotation called bind to the label property, and the bind property has two attributes: datasource and value.

If the annotation name is not specified, the name is assumed to be default. For example, the following two statements are equivalent:

<listitem label="@{datasource='foo'}"/>
<listitem label="@{default(datasource='foo')}"/>

If the attribute name is not specified, it is assumed to be value. For example, the following two statements are equivalent:

<listitem label="@{bind(foo)}"/>
<listitem label="@{bind(value='foo')}"/>

Here is a more complex example.

<listitem label="@{selected.name}"/>

where it 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. In other words, it is equivalent to the following code snippet.

<listitem label="@{default(value='selected.name')}"/>

To annotate the same property with multiple annotations, you could specify them one-by-one and separated with a space, as shown below.

<listitem label="@{ann1(selected.name) ann2(attr2a='attr2a',attr2b)}"/>

Annotate Components

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.

Version History

Last Update : 2010/11/17


Version Date Content
     



Last Update : 2010/11/17

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