The Common-Controls Tag Library


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 Examples of this are <forms:form> and <forms:section>

Body content: JSP
Tag class: ForEachTag

[ Syntax ]

Standard Syntax
[ id = "String" ]
[ indexId = "String" ]
[ name = "String" ]
[ property = "String" ]
[ scope = "{any | page | request | session | application}" ]
...Body Content...


[ Attributes ]

idString 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.

indexIdString The name of the index which is of type integer.

Annotation: Creates a Java variable. Does not allow an EL Expression!

nameString 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.

propertyString 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.

scopeHTTPScope 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=""               prefix="html" %>
<%@ taglib uri=""      prefix="base" %>
<%@ taglib uri=""      prefix="forms" %>

<html:form action="/sample815/foreachdemo">





      <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!  --%>





                  <%--  the "/completedOptions" syntax will access the option list in the surrounding form bean scope!  --%>
                  <base:options property="/completedOptions"/>



      <forms:buttonsection default="btnCancel">
            onclick="alert('Not supported'); return false;"/>

            onclick="alert('Not supported'); return false;"/>