Search code examples
javajasper-reportsrapidclipse

call JasperReports report by RapidClipseX


For RapidClipse4 I used following code to call and open a JasperReport in a new window

try {
    this.browserFrame = new XdevBrowserFrame();
    final Resource exportToResource = Report.New()
        .jrxml("WebContent/WEB-INF/resources/reports/MeinReport.jrxml")
        .dataSource( com.xdev.dal.DAOs.get(com.MyReportDAO.class)
                            .parameter("selJahr", selJahr)
                            .mapField("L1_GroupName", "l1GroupName")
                            .mapField("L2_GroupName", "l2GroupName").mapField("dBetrag", "dbetrag")
                            .mapField("JahrMonat", "jahrMonat")
            .exportToResource(ExportType.PDF);

        this.browserFrame.setSource(exportToResource);

} catch (final Exception e) {
    e.printStackTrace();
}

A few months ago I switched to RapidClipseX. But the used code did not more work.

Are there any experience/ sample code to

  • call a JasperReport out of a RapidClipseX Webapplication?
  • open it in a new window as pdf?

Solution

  • Here is a small example:

    final StreamResource pdf = Report.New()
            .dataSource(new ArrayList<>())
            .jrxml("/Simple.jrxml")
            .exportToResource(Format.Pdf());
    
    final HtmlObject pdfViewer = new HtmlObject(pdf, "application/pdf");
    pdfViewer.setSizeFull();
    
    this.add(pdfViewer);
    

    Also a useful tip: When you are in the code view, in the top left there is a "Report" entry in the code palette. When you click this button a wizard will open that will help you create the code needed to import a jasper report.