The ForEach servlet bean used in the previous sections is one of many servlet beans that Oracle Commerce provides. Among those most often used are the following:

Looping servlet beans

Several standard servlet beans are similar to ForEach: they also provide ways to loop through array elements. They differ from ForEach primarily in the portion of the array they render, or how they format output. For example:

  • Range renders a subset of array elements.

  • TableForEach produces output in a two-dimensional format such as an HTML table.

  • TableRange renders a subset of array elements, and produces its output in a two-dimensional format.

For a descriptions of all ATG servlet beans, see Appendix B: ATG Servlet Beans.

Switch Servlet Bean

Switch is a commonly used servlet bean that tests multiple open parameters against the input parameter value; if the open parameter and value parameter are identical, the servlet executes the open parameter’s body.

For example, your site might recognize different user types and render content accordingly. You typically use Switch servlet beans to handle this.

Switch takes an input parameter called value and renders the open parameter whose name matches value. A Switch servlet bean can have any number of open parameters, depending on the number of possible values of value. You can optionally include an open parameter named default that is rendered if value does not match the name of any other open parameter.

In the following example, the Switch servlet bean gets the value of currentStudent.gradtype. If the value of this parameter is grad or undergrad, Switch executes the Redirect servlet in the corresponding oparam body and displays the appropriate JSP. If no match is found in any open parameter, Switch renders the default open parameter, which redirects the user to the welcome page:

<dsp:droplet name="/atg/dynamo/droplet/Switch">
  <dsp:param name="value" param="currentStudent.gradtype"/>

  <dsp:oparam name="default">
    <dsp:droplet name="/atg/dynamo/droplet/Redirect">
       <dsp:param name="url" value="http://www.umvs.edu/welcome.jsp"/>
    </dsp:droplet>
  </oparam>

  <dsp:oparam name="undergrad">
    <dsp:droplet name="/atg/dynamo/droplet/Redirect">
       <dsp:param name="url" value="http://www.umvs.edu/enrollment_ugrad.jsp"/>
    </dsp:droplet>
  </oparam>

  <dsp:oparam name="grad">
    <dsp:droplet name="/atg/dynamo/droplet/Redirect">
       <dsp:param name="url" value="http://www.umvs.edu/enrollment_grad.jsp"/>
    </dsp:droplet>
  </oparam>
</dsp:droplet>

See Switch in Appendix B: ATG Servlet Beans for more information.


Copyright © 1997, 2015 Oracle and/or its affiliates. All rights reserved. Legal Notices