can you share how to use jasper file .jasper instead of dynamic jasper.
Unfortunately, I don’t have an example ready. Maybe you can take a look at the code of the PrintPreviewReport
class and an existing Jasper Reports example and figure out a solution. Not sure how easy that would be to be honest, but if it requires some kind of changes in the add-on, please let me know. Cheers!
Thanks for your reply and I have succeeded to use .jasper files. I did before with ZK using AMedia and the method is working in Vaadin.
Could you share how you did it? share the code…I have a .jasper file and I want to export it to pdf format
Connection conn = DBConnection.connect();
//parameters that needed to be passed inside jasper file
HashMap hm = new HashMap();
hm.put("ID", id);
hm.put("DATE", LocalDate);
dir = FileDirectory.REPORT_DIR + "file.jasper";
filename = "file.pdf";
try {
JasperPrint jpReport = JasperFillManager.fillReport(dir, hm, conn);
reportFile = File.createTempFile("output", ".pdf");
JasperExportManager.exportReportToPdfFile(jpReport, reportFile.getAbsolutePath());
} catch (JRException ex) {
Logger.getLogger(PayrollRegisterReportPDF.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex){
Logger.getLogger(PayrollRegisterReportPDF.class.getName()).log(Level.SEVERE, null, ex);
}
StreamResource resource = new StreamResource(filename, () -> getInputStream(reportFile));
resource.setContentType("application/pdf");
add(new EmbeddedPdfDocument(resource));
private FileInputStream getInputStream(File file){
try {
FileInputStream fis = new FileInputStream(file);
return fis;
} catch (FileNotFoundException e) {
e.getMessage();
return null;
}
}
This is for PDF View…
@Tag("object")
public class EmbeddedPdfDocument extends Component implements HasSize {
public EmbeddedPdfDocument(StreamResource resource) {
this();
getElement().setAttribute("data", resource);
}
public EmbeddedPdfDocument(String url) {
this();
getElement().setAttribute("data", url);
}
protected EmbeddedPdfDocument() {
getElement().setAttribute("type", "application/pdf");
setHeight("100%");
setWidth("100%");
}
}
Thanks Jet Beray for sharing this. Would you like to contribute it to the official documentation of the add-on? https://github.com/alejandro-du/report-ui/blob/master/README.md