The "multiForEach" tag is a looping tag, like the forEach tag, but it can operate on multiple Collections simultaneously. This tag must contain a body. The tag's block of cells is copied once for each collection element found in the largest of the collections. If a Collection is exhausted before another Collection, then "pastEndAction rules" apply. If only one Collection is specified, then the behavior is equivalent to a forEach tag.
There are 2 Managers and there are 3 Departments. Notice the blank cells below the end of the display for the managers.
Manager First Name | Manager Last Name | Manager Salary | Department ID | Department Name | Department Floor |
<jt:multiForEach collections="${managers};${departments}" vars="mgr;dept">${mgr.firstName} | ${mgr.lastName} | ${mgr.salary} | ${dept.id} | ${dept.name} | ${dept.floor}</jt:multiForEach> |
...gets transformed into...
Manager First Name | Manager Last Name | Manager Salary | Department ID | Department Name | Department Floor |
Robert | Stack | $1000.00 | 101 | Application Development | 5 |
Bugs | Bunny | $1500.00 | 102 | Human Resources | 4 |
103 | Quality Assurance | 5 |
Here's an example that uses the "pastEndAction" attribute. Notice how the "remove" value removes all formatting, including the merged region, past the end of the managers collection. If the "pastEndAction" attribute was not specified, or it was specified as the default value "clear", then the cells would be blank, but the merged region (plus any other borders and formatting) would remain.
Manager Name | Manager Salary | Department ID | Department Name | Department Floor | |
<jt:multiForEach collections="${managers};${departments}" vars="mgr;dept" pastEndAction="remove">${mgr.lastName}, ${mgr.firstName} | ${mgr.salary} | ${dept.id} | ${dept.name} | ${dept.floor}</jt:multiForEach> | |
...gets transformed into...
Manager Name | Manager Salary | Department ID | Department Name | Department Floor | |
Stack, Robert | $1000.00 | 101 | Application Development | 5 | |
Bunny, Bugs | $1500.00 | 102 | Human Resources | 4 | |
103 | Quality Assurance | 5 | |||
Another example uses the "replaceExpr" value and the "replaceValue" attribute to replace those expressions past the end of the managers collection. If the "replaceValue" attribute wasn't specified, then the expressions would be replaced by an empty string instead of a "-". The value of the attribute "replaceValue" can itself be an expression, e.g. replaceValue="${replVal}".
Manager Name | Manager Salary | Department ID | Department Name | Department Floor | |
<jt:multiForEach collections="${managers};${departments}" vars="mgr;dept" pastEndAction="replaceExpr" replaceValue="-" >${mgr.lastName}, ${mgr.firstName} | ${mgr.salary} | ${dept.id} | ${dept.name} | ${dept.floor}</jt:multiForEach> | |
...gets transformed into...
Manager Name | Manager Salary | Department ID | Department Name | Department Floor | |
Stack, Robert | $1000.00 | 101 | Application Development | 5 | |
Bunny, Bugs | $1500.00 | 102 | Human Resources | 4 | |
-, - | - | 103 | Quality Assurance | 5 | |