Implicit Sheet Cloning

When a collection expression such as those used in implicit collections processing appears in a sheet name, implicit sheet cloning is the result.

If JETT detects that an Expression on a sheet name contains operations on a Collection, then it clones the sheet, resulting in one cloned sheet per collection item.

In this example, "emps" is a List of Employees. The List doesn't have the properties "lastName", "firstName", "salary", and "manager" (methods getLastName(), getFirstName(), getSalary(), and getManager()). The implicit sheet cloning gets these properties from each item of the "employees" list. The sheet name here, ${emps.fullName}, contains the collection expression. One sheet is created for each of the 4 employees.

Employee ${emps.lastName}, ${emps.firstName}
Salary ${emps.salary}
Manager <jt:if test="${emps.getManager() != null}" then="${emps.manager.lastName}, ${emps.manager.firstName}"/>
${emps.fullName}  

...gets transformed into the four sheets...

Employee Stack, Robert
Salary $1000.00
Manager  
Robert Stack Suzie Queue Elmer Fudd Bugs Bunny

 

Employee Queue, Suzie
Salary $900.00
Manager Stack, Robert
Robert Stack Suzie Queue Elmer Fudd Bugs Bunny

 

Employee Fudd, Elmer
Salary $800.00
Manager Stack, Robert
Robert Stack Suzie Queue Elmer Fudd Bugs Bunny

 

Employee Bunny, Bugs
Salary $1500.00
Manager  
Robert Stack Suzie Queue Elmer Fudd Bugs Bunny

Changing Behavior with Metadata

To change the default behavior of implicit sheet cloning, include metadata at the end of an Expression that contains a reference to a Collection. Metadata may influence the affected sheet, by limiting the number of collection items and/or introducing status variables. The metadata key "?@" cannot be used in implicit sheet cloning, because Excel prevents the "?" character from being used in sheet names. Instead, append the string "$@" plus key/value pairs to the end of the Expression, separated by semicolons.

Metadata Keys

Most metadata keys that exist in implicit collections processing don't make sense in this context, but a few do. The keys that do apply here are abbreviated to one character, to maximize the space utilized by Excel's 31-character limit on sheet names.

  • r: String Optional. All pastEndAction values are implicitly replaceExpr in implicit sheet cloning. All expressions that reference collections that have been exhausted are replaced with this value. Default: an empty string. This acts just like the "replaceExpr" metadata key of implicit collections processing.
  • i: int Optional. Expose a zero-based "looping" variable name in the beans map. This acts just like the "indexVar" metadata key of implicit collections processing.
  • l: int Optional. Limit the number of collection items displayed to this number, for all collections found. This acts just like the "limit" metadata key of implicit collections processing.
  • v: String Optional. Expose a variable in the beans map that contains information about the current loop iteration -- the 0-based iteration index, whether it's the first iteration, and whether it's the last iteration. This acts just like the "varStatus" metadata key of implicit collections processing.

Once JETT has determined that it will perform implicit sheet cloning, it will scan the entire sheet for any references to any Collections in any Expression. Then, it will clone the sheet as many times as necessary. Each sheet receives the appropriate collection item exposed in the beans map for transformation.