List footerSubreportsList = DJConstants.FOOTER.equals(position)
? columnsGroup.getFooterSubreports()
: columnsGroup.getHeaderSubreports();
for (Iterator iterator = footerSubreportsList.iterator(); iterator.hasNext();) {
Subreport sr = (Subreport) iterator.next();
JRDesignSubreport subreport = new JRDesignSubreport(new JRDesignStyle().getDefaultStyleProvider());
//The data source
subreport.setDataSourceExpression(ExpressionUtils.getDataSourceExpression(sr.getDatasource()));
// int random_ = subReportRandom.nextInt();
//the subreport design
String paramname = sr.getReport().toString(); //TODO ensure this name is unique among all possible subreports
((DynamicJasperDesign)getDesign()).getParametersWithValues().put(paramname, sr.getReport());
String expText = "("+JasperReport.class.getName()+")$P{REPORT_PARAMETERS_MAP}.get( \""+ paramname +"\" )";
JRDesignExpression srExpression = ExpressionUtils.createExpression(expText, JasperReport.class);
subreport.setExpression(srExpression );
//set the parameters
subreport.setParametersMapExpression(ExpressionUtils.getParameterExpression(sr));
//some other options (cosmetical)
//subreport.setStretchType(JRDesignElement.STRETCH_TYPE_NO_STRETCH);
int offset = findVerticalOffset(band);
subreport.setY(offset);
subreport.setX(-getReport().getOptions().getLeftMargin().intValue());
subreport.setWidth(getReport().getOptions().getPage().getWidth());
subreport.setHeight(100);
subreport.setPositionType(JRElement.POSITION_TYPE_FIX_RELATIVE_TO_TOP);
subreport.setStretchType(JRElement.STRETCH_TYPE_NO_STRETCH);
if (sr.getStyle() != null)
applyStyleToElement(sr.getStyle(), subreport);
//adding to the band
band.addElement(subreport);
}
}