choose
The choose
command creates a set of conditional sections, of which only one will have its commands evaluated.
There should be one or more when
commands as children, each with its own condition. If the condition of one of them evaluates to a Boolean true
, the children of that when
are evaluated and the remaining children of choose
are skipped. Otherwise that when
is skipped and the condition of the next when
command is evaluated.
The last child of choose
may be an otherwise
command. Its contents will be processed if all of the preceding when
commands were skipped.
Child commands
when
Required. At least one of these is required to be amongchoose
's children.otherwise
Optional. Oneotherwise
can be a child ofchoose
. Preferably as the last child after thewhen
commands.
Examples
The choose
command must be used with the when
and otherwise
commands as its children.
<choose>
<when test="${oppLineItem.Quantity >= 1000}">
<set var="quantityDesc" value="High">
<when test="${oppLineItem.Quantity < 10}">
<set var="quantityDesc" value="Low">
<otherwise>
<set var="quantityDesc" value="Medium">
Note that the order of the child commands matters. The otherwise
command always finishes the evaluation of choose
, so any when
commands after an otherwise
never do anything. In this example of how not to do things, the "response" variable will never end up having "Yes." as its value.
<choose>
<otherwise>
<set var="response" value="No. Ask again later.">
<when test="${areWeThereYet}">
<set var="response" value="Yes.">