IsEmpty
The IsEmpty servlet bean is very useful in ATG world where we have to render content conditionally based value for bean.
/atg/dynamo/droplet/IsEmpty
The IsEmpty servlet bean conditionally renders one of its open parameters based on the value of its value input parameter. If value is null or if the object is empty, then the output parameter true is rendered. Otherwise, the output parameter false is rendered.
This example displays the a user’s hobbies, using the ForEach servlet bean to render them. If a user identifies no hobbies, a message displays:
<dsp:droplet name="IsEmpty">
<dsp:param name="value" bean="MyProfile.hobbies"/>
<dsp:oparam name="false">
Your hobbies are:
<dsp:droplet name="ForEach">
<dsp:param name="array" bean="MyProfile.hobbies"/>
<dsp:oparam name="output">
<dsp:valueof param="element"/>
</dsp:oparam>
</dsp:droplet>
</dsp:oparam>
<dsp:oparam name="true">
All work and no play makes Jack a dull boy.
</dsp:oparam>
</dsp:droplet>
Switch
Displays one of several possible outputs, depending on input parameter 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.
/atg/dynamo/droplet/Switch
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.
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>
/atg/commerce/catalog/SKULookup
/atg/dynamo/droplet/Switch
/atg/commerce/ShoppingCart
/atg/dynamo/droplet/Range
/atg/dynamo/droplet/ForEach
/atg/dynamo/droplet/IsEmpty
The IsEmpty servlet bean is very useful in ATG world where we have to render content conditionally based value for bean.
/atg/dynamo/droplet/IsEmpty
The IsEmpty servlet bean conditionally renders one of its open parameters based on the value of its value input parameter. If value is null or if the object is empty, then the output parameter true is rendered. Otherwise, the output parameter false is rendered.
This example displays the a user’s hobbies, using the ForEach servlet bean to render them. If a user identifies no hobbies, a message displays:
<dsp:droplet name="IsEmpty">
<dsp:param name="value" bean="MyProfile.hobbies"/>
<dsp:oparam name="false">
Your hobbies are:
<dsp:droplet name="ForEach">
<dsp:param name="array" bean="MyProfile.hobbies"/>
<dsp:oparam name="output">
<dsp:valueof param="element"/>
</dsp:oparam>
</dsp:droplet>
</dsp:oparam>
<dsp:oparam name="true">
All work and no play makes Jack a dull boy.
</dsp:oparam>
</dsp:droplet>
Switch
Displays one of several possible outputs, depending on input parameter 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.
/atg/dynamo/droplet/Switch
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.
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>
/atg/commerce/catalog/SKULookup
/atg/dynamo/droplet/Switch
/atg/commerce/ShoppingCart
/atg/dynamo/droplet/Range
/atg/dynamo/droplet/ForEach
/atg/dynamo/droplet/IsEmpty
No comments:
Post a Comment