カスタム属性のセットを定義します。custom属性は特定の領域と関係するオブジェクトです。使用できる領域はコンポーネント、スペース、ページ、デスクトップ、セッション、アプリケーションです。
以下に示したように、custom-attributesはプログラムなしでcustom属性を指定するのに便利です。
<window> <custom-attributes main.rich="simple" very-simple="intuitive"/> </window>
上記は以下と同じ働きをします。
<window> <zscript> self.setAttribute("main.rich", "simple"); self.setAttribute("very-simple", "intuitive"); </zscript> </window>
さらに、 custom属性を割り当てる領域を指定します。
<window id="main" title="Welcome"> <custom-attributes scope="desktop" shared="${main.title}"/> </window>
上記は下記と同様の働きをします。
<window id="main"> <zscript> desktop.setAttribute("shared", main.title); </zscript> </window>
ここで注意してほしいのは、EL表記はコンポーネントが作成されているときに評価されます。例えば、以下の例で${componentScope.simple}がnullと処理されます。どうしてでしょうか?それは<label value="${componentScope.simple}"/>のショートカットです。つまり、ELが評価されるとき、コンポーネントselfはウィンドウというより、ラベルです。
<window> <custom-attributes simple="intuitive"/> ${componentScope.simple} </window>
記は下記と同様の働きをします。
<window> <custom-attributes simple="intuitive"/> <label value="${componentScope.simple}"/><!-- self is label not window --> </window>
【ヒント】: attributeとcustom-attributesを混同しないよう注意してください。その二つに関係ありません。Attribute要素は閉じるためのXML属性を定義する一つの方法です。一方、custom-attributes要素はcustom属性を特定の領域に割り当てます。
Attribute Name |
Description |
---|---|
scope |
[Optional][Default: component] カスタム属性を関連付ける領域を指定する。 |
composite |
[Optional][Default: none] Specifies the format of the value. It could be none, list or map. Refer to the variables Element section above for more information. |
if |
[Optional][Default: none] 要素を評価する条件を定義します。 |
unless |
[Optional][Default: none] 要素を評価しない条件を定義します。 |