JETT's integration with the jAgg project allows the use of the "agg" tag, which performs aggregate operations on a List of items, yielding aggregate results that can be populated in the resultant spreadsheet. The "agg" tag requires a body.
The AggregateFunctions specified in the "aggs" attribute may be an AggregateFunction, either built-in to the jAgg library, or custom built by the developer.
Usually, a forEach tag is used inside the body of the "agg" tag to display the aggregate results.
A List of Employees is available in the beans map.
Title | Employee Count | Total Salary | Average Salary |
<jt:agg items="${employees}" aggs="Count(*);Sum(salary);Avg(salary)" aggsVar="aggs" valuesVar="results" groupBy="title"><jt:forEach items="${results}" var="result">{result.object.title} | ${result.getAggregateValue(aggs[0])} | ${result.getAggregateValue(aggs[1])} | ${result.getAggregateValue(aggs[2])}</jt:forEach></jt:agg> |
One can refer to aggregate values by passing in the indexed AggregateFunction or by passing the index itself into the "getAggregateValue" method. Alternatively, the template above could pass the index itself:
Title | Employee Count | Total Salary | Average Salary |
<jt:agg items="${employees}" aggs="Count(*);Sum(salary);Avg(salary)" aggsVar="aggs" valuesVar="results" groupBy="title"><jt:forEach items="${results}" var="result">{result.object.title} | ${result.getAggregateValue(0)} | ${result.getAggregateValue(1)} | ${result.getAggregateValue(2)}</jt:forEach></jt:agg> |
...Either way, it gets transformed into...
Title | Employee Count | Total Salary | Average Salary |
Data Structures Programmer | 2 | $2300.00 | $1150.00 |
Cartoon Character | 2 | $1900.00 | $950.00 |
This template specifies a rollup operation. Subtotals are calculated beginning with the rightmost property specified, and ending with the leftmost property specified (grand totals). Notice how the "isGrouping" method is used to determine whether the property value represents "All Values". Also, notice that specifying rollup="${[0,1]}" is equivalent to groupingSets="${[[0, 1], [0], []]}".
Is A Manager | Title | Total Salary |
<jt:agg items="${employees}" aggs="Sum(salary)" valuesVar="values" groupBy="isManager();title" rollup="${[0,1]}"> <jt:forEach items="${values}" var="value" orderBy="getPropertyValue(0);getPropertyValue(1)"> ${value.isGrouping(0) ? 'All Values' : value.getPropertyValue(0)} | ${value.isGrouping(1) ? 'All Values' : value.getPropertyValue(1)} | ${value.getAggregateValue(0])}</jt:forEach></jt:agg> |
Gets transformed into...
Is A Manager | Title | Total Salary |
FALSE | Cartoon Character | $800.00 |
FALSE | Data Structures Programmer | $900.00 |
FALSE | All Values | $1,700.00 |
TRUE | Cartoon Character | $1,500.00 |
TRUE | Data Structures Programmer | $1,000.00 |
TRUE | All Values | $2,500.00 |
All Values | All Values | $4,200.00 |
This template specifies multiple rollup operations. Each rollup combination is itself rolled up with the other rollup combinations. Notice that specifying rollups="${[[1], [2]]}" is equivalent to groupingSets="${[[0], [0, 1], [0, 2], [0, 1, 2]]}".
Is A Manager | Title | Catch Phrase | Total Salary |
<jt:agg items="${employees}" aggs="Sum(salary)" valuesVar="values" groupBy="isManager();title;catchPhrase" rollups="${[[1], [2]]}"><jt:forEach items="${values}" var="value" orderBy="getPropertyValue(0);getPropertyValue(1);getPropertyValue(2)"> ${value.isGrouping(0) ? 'All Values' : value.getPropertyValue(0)} | ${value.isGrouping(1) ? 'All Values' : value.getPropertyValue(1)} | ${value.isGrouping(2) ? 'All Values' : value.getPropertyValue(2)} | ${value.getAggregateValue(0)}</jt:forEach></jt:agg> |
Gets transformed into...
Is A Manager | Title | Catch Phrase | Total Salary |
FALSE | Cartoon Character | I'm hunting wabbits! Huh-uh-uh! | $800.00 |
FALSE | Cartoon Character | All Values | $800.00 |
FALSE | Data Structures Programmer | $900.00 | |
FALSE | Data Structures Programmer | All Values | $900.00 |
FALSE | All Values | I'm hunting wabbits! Huh-uh-uh! | $800.00 |
FALSE | All Values | $900.00 | |
FALSE | All Values | All Values | $1,700.00 |
TRUE | Cartoon Character | Ah, what's up doc? | $1,500.00 |
TRUE | Cartoon Character | All Values | $1,500.00 |
TRUE | Data Structures Programmer | $1,000.00 | |
TRUE | Data Structures Programmer | All Values | $1,000.00 |
TRUE | All Values | Ah, what's up doc? | $1,500.00 |
TRUE | All Values | $1,000.00 | |
TRUE | All Values | All Values | $2,500.00 |
This template specifies a data cube operation. Each property combination is computed from all properties specified. Notice that specifying cube="${[0, 1, 2]}" is equivalent to groupingSets="${[[], [0], [1], [2], [0, 1], [0, 2], [1, 2], [0, 1, 2]]}".
Is A Manager | Title | Catch Phrase | Total Salary |
<jt:agg items="${employees}" aggs="Sum(salary)" valuesVar="values" groupBy="isManager();title;catchPhrase" cube="${[0, 1, 2]}"><jt:forEach items="${values}" var="value" orderBy="getPropertyValue(0);getPropertyValue(1);getPropertyValue(2)"> ${value.isGrouping(0) ? 'All Values' : value.getPropertyValue(0)} | ${value.isGrouping(1) ? 'All Values' : value.getPropertyValue(1)} | ${value.isGrouping(2) ? 'All Values' : value.getPropertyValue(2)} | ${value.getAggregateValue(0)}</jt:forEach></jt:agg> |
Gets transformed into...
Is A Manager | Title | Catch Phrase | Total Salary |
FALSE | Cartoon Character | I'm hunting wabbits! Huh-uh-uh! | $800.00 |
FALSE | Cartoon Character | All Values | $800.00 |
FALSE | Data Structures Programmer | $900.00 | |
FALSE | Data Structures Programmer | All Values | $900.00 |
FALSE | All Values | I'm hunting wabbits! Huh-uh-uh! | $800.00 |
FALSE | All Values | $900.00 | |
FALSE | All Values | All Values | $1,700.00 |
TRUE | Cartoon Character | Ah, what's up doc? | $1,500.00 |
TRUE | Cartoon Character | All Values | $1,500.00 |
TRUE | Data Structures Programmer | $1,000.00 | |
TRUE | Data Structures Programmer | All Values | $1,000.00 |
TRUE | All Values | Ah, what's up doc? | $1,500.00 |
TRUE | All Values | $1,000.00 | |
TRUE | All Values | All Values | $2,500.00 |
All Values | Cartoon Character | Ah, what's up doc? | $1,500.00 |
All Values | Cartoon Character | I'm hunting wabbits! Huh-uh-uh! | $800.00 |
All Values | Cartoon Character | All Values | $2,300.00 |
All Values | Data Structures Programmer | $1,900.00 | |
All Values | Data Structures Programmer | All Values | $1,900.00 |
All Values | All Values | Ah, what's up doc? | $1,500.00 |
All Values | All Values | I'm hunting wabbits! Huh-uh-uh! | $800.00 |
All Values | All Values | $1,900.00 | |
All Values | All Values | All Values | $4,200.00 |
This template contains super aggregate operations representing specific grouping sets. Such grouping sets do not necessarily have anything to do with each other.
Is A Manager | Title | Catch Phrase | Total Salary |
<jt:agg items="${employees}" aggs="Sum(salary)" valuesVar="values" groupBy="isManager();title;catchPhrase" groupingSets="${[[0], [1, 2]]}"><jt:forEach items="${values}" var="value"> ${value.isGrouping(0) ? 'All Values' : value.getPropertyValue(0)} | ${value.isGrouping(1) ? 'All Values' : value.getPropertyValue(1)} | ${value.isGrouping(2) ? 'All Values' : value.getPropertyValue(2)} | ${value.getAggregateValue(0)}</jt:forEach></jt:agg> |
Gets transformed into...
Is A Manager | Title | Catch Phrase | Total Salary |
FALSE | All Values | All Values | $1,700.00 |
TRUE | All Values | All Values | $2,500.00 |
All Values | Cartoon Character | Ah, what's up Doc? | $1,500.00 |
All Values | Cartoon Character | I'm hunting wabbits! Huh-uh-uh! | $800.00 |
All Values | Data Structures Programmer | $1,900.00 |
Notice that the first two data rows represent the grouping set "[0]" and the last three data rows represent the grouping set "[1, 2]".