You can make servlet bean parameters available to other EL-enabled tags by setting the servlet bean’s var attribute:

<dsp:droplet name="servlet-bean-path" var="attr-name">
   ...
</dsp:droplet>

The var attribute creates a Map that is composed of the parameters and their values defined in the enclosing dsp:droplet tag, and provides a name to that Map.

For example, you can modify the previous ForEach example as follows:

<dsp:droplet name="/atg/dynamo/droplet/ForEach" var="fe">
    <dsp:param name="array" bean="/samples/Student_01.subjects"/>
    <dsp:oparam name="outputStart">
        <p>The student is registered for these courses:
        <ul>
    </dsp:oparam>
    <dsp:oparam name="output">
        <li><c:out value="${fe.element}"/></li>
    </dsp:oparam>
  <dsp:oparam name="outputEnd">
    </ul>
  </dsp:oparm>
</dsp:droplet>

In this example, the JSTL Core tag c:out replaces the dsp:valueof tag and uses EL syntax to render the property contents.

A servlet bean’s var attribute can be set either to page (the default) or request scope. In general, it is good practice to confine the scope of a servlet bean’s var attribute to the current page.

Scope of servlet bean parameters

If you set EL variables for nested servlet beans, each variable is accessible only within the bean where it was set and to its parameters, even if several variables use the same name. For example, in the following example, the dsp:droplet tags for both servlet beans set the EL variable fe. Each instance of fe has scope only within its own bean; so, the first-set fe is accessible only to outer-bean parameters, while the second instance of fe is accessible only to inner-bean parameters:

<dsp:droplet name="/atg/dynamo/droplet/ForEach var="fe">
…
     <dsp:droplet name="/atg/dynamo/droplet/ForEach" var="fe">
      …
     </dsp:droplet>
…
</dsp:droplet>

For more information, see Nesting Servlet Beans.

 
loading table of contents...