Skip to main content

         This documentation site is for previous versions. Visit our new documentation site for current releases.      

forEach JavaServer Page tag

Updated on August 10, 2022

Use the forEach tag to repeat an action for each property in a page, for each page in a Page List, or for each property in any list or group.

In runtime stream processing that includes a section or control that includes complex parameters on the Parameters tab, you can use the forEach tag to iterate over arrays or groups of parameter values.


Properties with a mode other than Single Value are known as aggregates. The forEach tag iterates through the parts of an aggregate property.

For example, assume a clipboard page named Operators contains embedded pxResults() pages. The pxResults() pages each hold a property pyUserIdentifier identifying one customer. Use the forEach tag to create an HTML table that contains a row for each customer:

<pega:forEach name="Operators.pxResults">
		<pega:reference name="$THIS.pyUserIdentifier" />
</pega:forEach >

Within the scope of the forEach tag, special keywords are available:

  • The keyword $this identifies the current (embedded) page.
  • The syntax $this.propertyname represents a property on the current (embedded) page.
  • The keyword $this-value represents the (scalar) current active property on the current embedded page.

Complete syntax

In the syntax presentations below:

  • Square bracket characters [ and ] define optional parts of the tag. Do not type the brackets.
  • JSP delimiters <pega..> and </pega...> mark the start and end of the tag.
  • Replace any text in italics with your choice of value of that type.

To do something for each property in a Value List, Value Group, Page, Page List, or Page Group, use this syntax. In place of the word aggregate-reference, enter the name of the aggregate property.

<pega:forEach name="aggregate-reference" >
	actionToRepeat or
</pega:forEach >
name The name of the aggregate property, $this, or $this.propertyname. To refer to a complex parameter, use the keyword "param" followed by the complex parameter name.

To do some processing for each property in a top-level page, use this syntax:

<pega:forEach name="page-name" >
</pega:forEach >

If the array contains only Single Value properties, use the keyword $this :

<pega:forEach name="$this">
</pega:forEach >

No conditional "break" or "leave" from the scope of a forEach tag is available: all iterations always occur. To perform only some, rather than all, iterations of a forEach tag, include a <pega:when > element:

<pega:forEach name="page-name" >
	<pega:when ...>
		actionToRepeat if true
</pega:forEach >

Nesting a forEach tag within the scope of another forEach tag is supported.

To iterate over complex parameters that are similar in structure to Value List, Value Group, Page List, and Page Group properties defined on the Parameters tab of a section or control rule:

<pega:forEach name="Param.MyPageList" >
	<pega:reference name="$this.Innervalue"/>


These examples use the forEach tag to display values from clipboard pages.

Arrays within arrays

If the array contains lists of pages, then you can embed a forEach tag and iterate over that list as well:

<pega:forEach name=”.pxResults”>
	<pega:forEach name=”$this.addresses”>
		<pega:reference name=”$this.streetName”/>
Obtain values for each assignment in a flow

To obtain values from an embedded group of pages:

<pega:forEach name=".pxFlow" >
	value="<pega:reference ref="$this.pxAssignmentKey" /> "
</pega:forEach >

This example uses the Work-.pxFlow property, a Page Group. It identifies, in sequence, the value of the pxAssignmentKey property for each page in the Page Group.

Using the forEach tag in control rules

To create a selection box, use syntax similar to the following:

<select name="<p:r n="$this-name" /> ">
<pega:forEach name=".pyKeyDefList" >
	<option value="<pega:reference ref="$this.pyKeyName" />">
<pega:reference ref="$this.pyKeyCaption" >
</pega:forEach >

To create option (radio) buttons, use syntax similar to the following:

<pega:withTarget name="$this" >
	<pega:forEach name=" .pyKeyDefList" >
		<input type="radio" value="<pega:reference
			ref="$this.pyKeyName" / >">
		<pega:reference ref="$this.pyKeyCaption" / >

An example of iteration over complex parameter values rather than property values:

<pega:forEach name="Param.MyPageList">
	<pega:withEmbedded name="$this" >
		<pega:reference name=".MyInnerValue" />

JavaServer Page tags

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best. is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us