ClassName

atg.droplet.Switch

Component

/atg/dynamo/droplet/Switch

The Switch servlet bean 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 of your open parameters to one value and the Switch servlet bean’s value parameter to the other.

Input Parameter

value
The value of the Switch. The Switch value is turned into a string and used as the name of the parameter to render. For example, if the Switch’s value parameter is a Boolean that is true, then Switch renders the value of its true parameter.

Open Parameters

possible values of value
There can be any number of open parameters whose names are the possible values of the value input parameter, converted to Strings. These parameters must be locally defined in the Switch invocation.

Note: The names of Switch open parameters cannot contain the dot (.) or backslash (/) character in their names or values. For example, the following open parameter is invalid, and is never rendered:

<dsp:oparam name="do.not.use.dots">
   This open parameter can't be rendered
</dsp:oparam>

unset
The value to render if the value parameter is not set. This parameter must be locally defined in the Switch invocation.

default
The parameter to render if the value parameter is not defined or its value (converted to a String) does not match any of the output parameters. This parameter must be locally defined in the Switch invocation.

Example

In this example, the ATG platform imports the Switch servlet bean with dsp:importbean. (See the Creating Documents chapter for information about using dsp:importbean.) For each person, this example outputs a row in a table, listing the person’s name, skill level, and whether the person has a car. Depending on the value of the person.hasCar parameter, the Switch servlet bean displays the capacity of the person’s car. A second use of the Switch servlet bean outputs 1 person if the car capacity is 1, and n people if the car capacity is other than 1.

<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>
 
loading table of contents...