ATG Page Developer’s Guide

Nesting Servlet Beans

The HTML produced by open parameters can contain dynamic elements such as dsp:valueof tags. The open parameters of one servlet bean can also include other servlet beans.

The following example specifies to display a list of students who live in a dormitory, and under each student name list registered courses. It does this by nesting ForEach servlet bean: the outer servlet bean displays the student names, and the inner servlet bean displays the courses.

The outer ForEach sets its array parameter to Markley.students, an array of Student components. The outer ForEach element points to the first Student component in this array.

The outer ForEach bean displays the current value of element.name, the name property of the current Student component.

The inner ForEach bean sets its array parameter to element.subjects. This parameter points to the first subjects String in the current Student component.

The inner ForEach bean iterates over the elements of its array parameter, displaying each String in element.subjects.

Note: The element parameter of a given servlet bean has scope only within that bean; changes to its value have no effect on the element parameters of servlet beans that are nested outside and inside the current bean.

After the inner ForEach processes all elements in element.subjects , it returns control to the outer ForEach.

The outer ForEach element parameter points to the second element of the Markley.students array.

Steps 3-5 repeat, this time using the next Student component.

This process continues for each component in the Markley.students array.

Referencing parameters in outer servlet beans

Servlet bean parameters have scope only within the bean itself. When nesting occurs, the parameters within each bean are unaffected by corresponding parameters in the outer- and inner-nested beans. However, an inner bean can access the values of an outer bean parameter by using to define another parameter in the outer servlet bean, and setting it to the value of a parameter in the current bean that the inner beans can access.

For example, you can modify the JSP shown earlier and obtain similar output, as follows: