A command library for creating conditional blocks. The if command is the basic tool for making optional logic, while the choose command with its associated child commands when and otherwise works well for creating mutually exclusive logic blocks.
If
forms a basic conditional block whose child commands are evaluated only if the expression in the test
attribute evaluates to a Boolean value of true
.
Child commands
Any command can be a child of if
. There should be at least one child, as a conditional block without content serves no purpose.
Attributes
test | ||
---|---|---|
Required |
Value type |
EL-evaluated |
Yes |
Boolean | Yes |
The conditional expression. Should the resolved value be true , the child tags are evaluated, otherwise they are not. |
Examples
To make use of if
, place the commands you wish to make conditional as its children. Make sure that the EL expression for the test
attribute evaluates into a Boolean value.
<if test="${mainOpportunity.IsClosed}">
<set var="statusMessage" value="Opportunity is closed.">
<next step="endScreen">
The choose
command presents a set of conditional blocks, of which only one will have its contents processed.
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 processed 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
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 choose
block, 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="Ask again later.">
<when test="${areWeThereYet}">
<set var="response" value="Yes.">
A child of a choose
command. The children of when
are evaluated if the condition of the test
attribute resolves to a Boolean true
.
Parent commands
-
choose
Required. This must be the parent command.
Child commands
Any command can be a child of when
. There should preferably be at least one child.
Attributes
test | ||
---|---|---|
Required |
Value type |
EL-evaluated |
Yes |
Boolean | Yes |
The conditional expression. Should the resolved value be true , the child commands are evaluated, otherwise they are not. |
Examples
See the documentation of choose for examples.
A child of a choose
command. The children of otherwise
are evaluated if the contents of none of the preceding when
command were evaluated.
Parent commands
-
choose
Required. This must be the parent command.
Child commands
Any command can be a child of otherwise
. There should preferably be at least one child.
Examples
See the documentation of choose for examples.
Comments
0 comments