Annotate in ZUML"
Line 3: | Line 3: | ||
= Annotate Properties = | = Annotate Properties = | ||
− | To annotate a property, you could specify an annotation expression as the value for the property | + | To annotate a property, you could specify an annotation expression as the value of the property. 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. |
+ | |||
+ | The format of an annotation expression is <tt>@{''annot-name''(''attr-name1''=''attr-value1, attr-name2=attr-value2'')}</tt>. That is, an annotation expression is an annotation enclosed with <tt>@{</tt> and <tt>}</tt>. An annotation consists of a name and a map of attributes which is enclosed with parenthesis. Each attribute is a pair of name-value. For example, | ||
<source lang="xml" > | <source lang="xml" > | ||
Line 9: | Line 11: | ||
</source> | </source> | ||
− | + | where an annotation called <tt>bind</tt> is annotated to the <tt>label</tt> property, and the <tt>bind</tt> annotation has two attributes: <tt>datasource</tt> and <tt>value</tt>. | |
− | |||
− | |||
− | |||
− | |||
− | If the annotation name is not specified, | + | If the annotation name is not specified, it is assumed to be <tt>default</tt>. For example, the following two statements are equivalent: |
<source lang="xml"> | <source lang="xml"> | ||
Line 41: | Line 39: | ||
</source> | </source> | ||
− | To annotate the same property with multiple annotations, you could specify them one-by-one and | + | To annotate the same property with multiple annotations, you could specify them one-by-one and separate them with a space, as shown below. |
<source lang="xml" > | <source lang="xml" > |
Revision as of 08:33, 17 November 2010
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 of the property. 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.
The format of an annotation expression is @{annot-name(attr-name1=attr-value1, attr-name2=attr-value2)}. That is, an annotation expression is an annotation enclosed with @{ and }. An annotation consists of a name and a map of attributes which is enclosed with parenthesis. Each attribute is a pair of name-value. For example,
<listitem label="@{bind(datasource='author',value='selected')}"/>
where an annotation called bind is annotated to the label property, and the bind annotation has two attributes: datasource and value.
If the annotation name is not specified, it 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 separate them 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
Version | Date | Content |
---|---|---|