SeamFramework.orgCommunity Documentation
Using Seam Reports is a simple four step process. These steps are the same regardless of the reporting engine being used.
Create a report using a favorite report editor
Load the created report
Fill the report with data
Render the report
Of course some of these steps will have different ways of accomplishing the task, but at a high level they are
all the same. For simplicity this quick start will use JasperReports and the first step will be assumed to have
already taken place and the report is available in the deployed archive. The location of the report isn't
important, the ability to pull it into an InputStream
is all that really matters.
The following code demonstrates a basic way of fulfilling the last three steps in using Seam Reports using JasperReports as the reporting engine. The report has already been created and is bundled inside the deployable archive. There are no paramaters for the report. The report is a simple listing of people's names and contact information.
@Model
public class PersonContactReport {@Inject @Resource("WEB-INF/jasperreports/personContact.jrxml")
private InputStream reportTemplate;@Inject @Jasper
private ReportCompiler reportCompiler;@Inject @Jasper @PDF
private ReportRenderer pdfRenderer;
@Inject
private EntityManager em;![]()
public OutputStream render() {
final Report filledReport = this.fillReport();
final OutputStream os = new ByteArrayOutputStream();
this.pdfRenderer.render(filledReport, os);
return os;
}![]()
private Report fillReport() {
final ReportDefinition rd = this.reportCompiler.compile(reportTemplate);
return rd.fill(this.createDatasource(), Collections.EMPTY_MAP);
}![]()
private JRDataSource createDatasource() {
final List<Person> personList = this.em.createQuery("select p from Person", Person.class).getResultList();
return new JRBeanCollectionDataSource(personList);
}
}
Solder allows easy resource injection for files available in the archive. This injects the report template which has been created previously (perhaps by someone else in the business) and added to the deployable archive. | |
A | |
This is an instance of using both a qualifer ( | |
The | |
At this stage data to populate the report is retrieved and added to the compiled
| |
This last stage of using Seam Reports is the only place that may require the application to use the report engine API. In this example a list of JPA entities is retrieved and added to a JasperReports datasource, which is then used by the calling method to populate the report template as mentioned above. |
There are four API level annotations to be aware of when using Seam Reports. All four of them declare metadata about objects that are being injected. They're also all CDI stereotypes which instruct the implementing renderer the mimetype that should be used.
CSV
HTML
XLS
XML
These annotations are only used when injecting a ReportRenderer
. Only one of them may be used
per renderer. Multiple renderers must be injected if multiple renderering types are desired.