I have a requirement to design in ireport.
I have three VOs
DeliveryAllocations {
private String collectorCode;
private String collectorName
This is done by for example using a subreport and passing as datasource
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{allocations})
Example code:
Main report (PlantVO.jrxml
)
Sub report (PlantAllocationVO_subreport
)
With main code
JasperReport report = JasperCompileManager.compileReport("PlantVO.jrxml");
Map map = new HashMap();
JasperPrint print = JasperFillManager.fillReport(report, map,new JRBeanCollectionDataSource(deliveryAllocations.getPlants()));
JasperExportManager.exportReportToPdfFile(print, "PlantVO.pdf");
Will produce this result:
Some design notes:
I would keep correct type of fields (es. weight
as a Double
or
Integer
) and apply pattern in jrxml (see example), this will help
you do correct export to excel.
TotalWeight
there is no really need to have this as a field, it could
be calculated by subreport and passed back to main report.
Have Fun