ClassName |
|
---|---|
Component |
|
The For
servlet bean implements a simple loop. Given an integer parameter howMany
, the For
servlet bean renders its output
parameter that many times. The howMany
parameter must be a String representation of an int. Each iteration sets the index
parameter to the current loop count, starting at 0, and sets the count
parameter to index + 1, starting at 1.
Input Parameter
howMany
The parameter that defines the number of times to render the output parameter.
Output Parameters
index
This optional parameter is set to the zero-based index of the current element
of the array each time that the output
parameter is rendered. The value of index
for the first iteration is 0.
count
This optional parameter is set to the one-based index of the current element
of the array each time that the output
parameter is rendered. The value of count
for the first iteration is 1.
Open Parameter
output
This optional parameter is rendered the number of times specified by the howMany
parameter.
Example
In this example, you present the user with textboxes, the number of which is user-determined. On the first page (code not shown) the user specifies how many text boxes they want to see. This value is stored in the form’s numChoices
property. On the second page (code excerpt included below), you use the For
servlet bean to display the number of textboxes the user wanted to see, by setting the howMany
attribute to the numChoices
property. The servlet bean uses the count
parameter to supply a consecutive number to each text box. When a user enters values into the text boxes, those values are saved to the form’s choice
property.
<dsp:droplet name="/atg/dynamo/droplet/For"> <dsp:param name="howMany" bean="SomeForm.numchoices"/> <dsp:oparam name="output"> Text box # <dsp:valueof param="count"/>: <dsp:input bean="SomeForm.choice[param:index]" type="text"/> <br/> </dsp:oparam> </dsp:droplet>