[UP] The UI language |
The element ui:cond This element contains several conditional branches. The first branch whose condition code evaluates to true is expanded. If no branch is true, nothing will be expanded. Declaration Level: Control structure <!ELEMENT ui:cond ( (ui:if | ui:ifexpr | ui:ifvar | ui:iflang | ui:true | ui:false)+ )> Sub elements The following sub elements are possible. All are conditional elements setting the condition code. Example <ui:cond> <ui:ifvar variable="v" value="1"> ...branch 1... </ui:ifvar> <ui:ifvar variable="v" value="2"> ...branch 2... </ui:ifvar> <ui:true> ...branch 3... </ui:true> </ui:cond>If the variable v has the value 1, the first branch will be expanded. If it has the value 2, the second branch will be expanded. In all other cases, the third branch will be expanded. Hints There is a certain order in which the various types of expansions are performed. First, template parameters and bracket expressions are evaluated and replaced by the resulting values. After that, the conditions are tested, and the right conditional branches are selected. This particular order may lead to problems when the test conditions are used to ensure preconditions of expressions, like in: <ui:if value1="$x" value2="0" op="int-gt"> $[div(100,$x)] <!-- Runtime Error! --> </ui:if>Here, the division is carried out before the test whether $x is positive, and because of this a runtime error can happen. The solution is to put the bracket expression into a template, as templates are expanded only on demand: <ui:template name="divide" from-caller="x"> $[div(100,$x)] </ui:template> ... <ui:if value1="$x" value2="0" op="int-gt"> <t:divide x="$x"/> </ui:if> |