<forms:forEach>

The tag will iterate over a given collection with objects.
Thereby the properties of the nested <form>-Tags
will be interpreted in the context of the current element
within the iteration. If a property should refer to the underling actionform
instead the current element within the collection, a "/" sign
needs to be prepended (Example: property="/roleOptions").
Also an EL Expression can be used to access the current element within the iteration.
Therefore the id-Attribute needs to be specified. After that you can refer to a
property like ${[id].property}. You can use this syntax to append the value to
a message resource like title="messageKey#${[id].property}" (see the full example below).
This can be used to display a message resource followed by the value from the property.
Therefore the messageKey should contain a placeholder. For example: "user.form.comments=Comment {0}".
The placeholder will be replaced by the value.
The tag may only be used within a com.cc.framework.taglib.forms.FormElementContainerTag
. Examples
of this are <forms:form> and <forms:section>

[ Syntax ]
Standard Syntax
<forms:forEach
[
id =
"String"
]
[
indexId =
"String"
]
[
name =
"String"
]
[
property =
"String"
]
[
scope =
"{
any | page | request | session | application}"
]
>
...Body Content...
</forms:forEach>
[ Attributes ]
Attribute | Type | Description | Req. | RTExp |
id | String |
Assigns the control element a unique identifier.
Using the given Id, the Java variable can be accessed
in the tag Body.
The id must be a string literal because the JSP
compiler generates a variable with this name at compile
time
Annotation:
A valid Java identifier must be given.
| |
|
indexId | String |
The name of the index which is of type integer.
Annotation:
Creates a Java variable. Does not allow an EL Expression!
| |
|
name | String |
Specifies the name of the Java-Bean. The Java-Bean must be stored
in the given scope.
When the tag is surrounded by a Struts <html:form> tag, no Bean Name need be
specified. In this case, the Java-Bean is drawn via a property of the Struts Form Bean.
Annotation:
A valid Java identifier must be given.
| |
|
property | String |
Specifies the name of the property using which the Java-Bean
is to be accessed. This is generally only necessary when the
Java-Bean is associated with a Struts Form Bean.
Annotation:
A valid Java identifier must be given.
| |
|
scope | HTTPScope |
This attribute shows the Scope in which the
Java-Bean with the actual display data can be found.
-
any
=
The Bean is searched for in ever Scope.
-
page
=
The Bean exists as a local variable in the JSP Page.
-
request
=
The Bean is in the HTTP-request.
-
session
=
The Bean is in the HTTP-Session.
-
application
=
The Bean is in the Servletkontext.
| |
|
[ Example ]
An iteration for different formelements using the forEach tag.
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://www.common-controls.com/cc/tags-base" prefix="base" %>
<%@ taglib uri="http://www.common-controls.com/cc/tags-forms" prefix="forms" %>
<html:form action="/sample815/foreachdemo">
<forms:form
type="edit"
caption="user.form.comment"
formid="frmEdit"
width="650"
help="HID-100">
<forms:row>
<forms:text
label="user.form.lname"
property="lastName"
size="15"
maxlength="20"
required="true"
help="HID-101"/>
<forms:text
label="user.form.fname"
property="firstName"
size="15"
maxlength="20"
required="true"
help="HID-102"/>
</forms:row>
<forms:forEach id="co" property="comments">
<%-- Make sure you have EL expressions enabled (web.xml >= 2.4)
otherwise the expression ${co.commentId} gets not evaluated!
--%>
<forms:section
title="user.form.comments#${co.commentId}">
<forms:plaintext
label="user.form.commentid"
property="commentId"/>
<forms:textarea
label="user.form.comment"
property="comment"
required="false"
cols="80"
rows="3"
help="HID-1001"
valign="top"/>
<forms:row>
<forms:calendar
label="user.form.untildate"
property="untilDate"
required="false"
help="HID-1002"/>
<forms:select
label="user.form.completed"
property="completed"
required="true"
help="HID-1003">
<%-- the "/completedOptions" syntax will access the option list
in the surrounding form bean scope!
--%>
<base:options property="/completedOptions"/>
</forms:select>
</forms:row>
</forms:section>
</forms:forEach>
<forms:buttonsection default="btnCancel">
<forms:button
name="btnSave"
text="button.title.save"
title="button.title.save"
onclick="alert('Not supported'); return false;"/>
<forms:button
name="btnBack"
text="button.title.back"
title="button.title.back"
onclick="alert('Not supported'); return false;"/>
</forms:buttonsection>
</forms:form>
</html:form>