Displays one of several possible outputs, depending on input parameter value.
Class Name |
|
---|---|
Component |
|
Required Input Parameters
value
The test value used to determine which output parameter to execute. The Switch value
is turned into a string and used as the name of the parameter to render. For example, if the value
parameter is a Boolean that is set to true, the Switch servlet bean executes the true
output parameter.
Open Parameters
You can define an open parameter for each possible value of the value
input parameter. For example, if the Switch value is a Boolean, you can define open parameters true
and false
as follows:
<dsp:oparam name="false"> ... </dsp:oparam> <dsp:oparam name="true"> ... </dsp:oparam>
Note: Open parameter names cannot embed dot (.) or backslash (/) characters in their names or values.
unset
The value to render if the value
parameter is empty.
default
Rendered if the value
parameter is undefined or its value (converted to a String) does not match any output parameters.
Usage Notes
Switch conditionally renders one of its open parameters based on the value of its value
input parameter. This value is turned into a string and used as the name of the parameter to render for this case. You can use Switch to compare two dynamically defined values by setting the name of one open parameter to one value and the Switch servlet bean’s value
parameter to the other.
Example
In this example, the ATG platform imports the Switch servlet bean with dsp:importbean
. For each person, this example outputs a row in a table that lists the person’s name, skill level, and whether the person has a car. Depending on the value of the person.hasCar
parameter, Switch displays the capacity of the person’s car. A second use of Switch outputs 1 person
if the car capacity is one, and n people
if the car capacity is a different value.
<dsp:importbean bean="/atg/dynamo/droplet/Switch"/> <tr> <td valign=top><dsp:valueof param="person.name"/></td> <td valign=top><dsp:valueof param="person.skillLevel"/></td> <td valign=top> <dsp:droplet name="Switch"> <dsp:param name="value" param="person.hasCar"/> <dsp:oparam name="false"> none </dsp:oparam> <dsp:oparam name="true"> can carry <dsp:valueof param="person.carCapacity"/> <dsp:droplet name="Switch"> <dsp:param name="value" param="carCapacity"/> <dsp:oparam name="1"> person</dsp:oparam> <dsp:oparam name="default"> people</dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> </td> </tr>