|
Re: How can i integrate jasper reports on scout? [message #1758013 is a reply to message #1755991] |
Wed, 22 March 2017 18:25   |
Eclipse User |
|
|
|
Jasper integration:
The integration is basically the same as in any other java/maven environment (lots of tuturials around).
- pom dependencies
Add the following dependencies to your project. Usually in the server parts pom file.
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.4.0</version>
<exclusions>
<exclusion>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<!-- <version>1.0-2</version> -->
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcmail-jdk14</artifactId>
</exclusion>
<exclusion>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>6.0.0</version>
</dependency>
- Report definition
Create a report definition (*.jrxml) e.g. using the report designer and put it into the <your module>/src/main/resources/jasper.
- Create the report
Could look like:
InputStream billStream = getClass().getResourceAsStream("/jasper/bill.jrxml");
try {
JasperReport jasperBillReport = JasperCompileManager.compileReport(billStream);
Map<String, Object> parameters = new HashMap<>();
// put parameters here
JRBeanCollectionDataSource connection = new JRBeanCollectionDataSource(CollectionUtility.arrayList(yourBean));
JasperPrint print = JasperFillManager.fillReport(jasperBillReport, parameters, connection);
return JasperExportManager.exportReportToPdf(print);
}
catch (JRException e) {
throw BEANS.get(PlatformExceptionTranslator.class).translate(e);
}
A sample implementation is available under Github Docbox.
-andreas
|
|
|
|
Re: How can i integrate jasper reports on scout? [message #1759956 is a reply to message #1758897] |
Thu, 20 April 2017 13:21  |
Eclipse User |
|
|
|
Hello Andreas,
Thank you for the helpful tips including the sample implementation.
I changed many things in my implementation but i successfully generated a jasper report and save it on database using a bytea field on postgres, i am having only a problem to retreive it and show on the browser
this the File field on my TablePage that i am using to retreive the content(pdf file)
public class FileColumn extends AbstractColumn<byte[]> {
@Override
protected String getConfiguredHeaderText() {
return TEXTS.get("File");
}
@Override
protected boolean getConfiguredHtmlEnabled() {
return true;
}
@Override
protected int getConfiguredWidth() {
return 100;
}
@Override
protected boolean getConfiguredVisible() {
return true;
}
@Override
protected void execDecorateCell(Cell cell, ITableRow row) {
StringBuilder linkBuilder = new StringBuilder();
linkBuilder.append(getFileColumn ().getValue(row));
String encodedHtml = HTML.link(linkBuilder, TEXTS.get("Open")).addAttribute("target", "_blank").toHtml();
cell.setHtmlEnabled(true);
cell.setText(encodedHtml);
}
}
Any ideia of how can i do it?
Thank you, Marco.
|
|
|
Powered by
FUDForum. Page generated in 0.02895 seconds