4.7. Enclosing Components

Some components have the ability to enclose text and other components that will render as dictated by the enclosing component. The enclosing component determines if, when and how often the enclosed text and components are rendered. The enclosed part is the body of the enclosing component. Whether a component is allowed to have a body is specified in the component specification. When not allowed, the component simply ignores the enclosed body.

Enclosed components are not to be confused with embedded components. Enclosed components still execute within the context of their containing component even though their rendering is controlled by their enclosing component.

...
<span jwcid="list@Foreach" ... > 1 
    Iteration # 2 
    <span jwcid="@Insert" value="ognl:components.list.index"> 3 
        123 4 
    </span>
    <br /> 5 
</span>
...

1

Foreach is an enclosing component. The body of the Foreach component is the text and components enclosed by the Foreach's placeholder tag.

2

This is static text enclosed by the Foreach component and will be rendered unaltered for each iteration of the loop.

3

The Insert component here is enclosed by the Foreach and will render the index of each iteration.

[Tip]Tip
The index of the current iteration can be obtained from the Foreach component itself via the components.list.index expression. components is a special property map of AbstractComponent that contains all the embedded components keyed on the respective component ids.

4

This is a static text enclosed by the Insert component. Insert components, according to their specification, do not allow bodies, so this text will be silently ignored.

5

This is markup text enclosed by the Foreach component and will be rendered unaltered for each iteration of the loop.