-1

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?
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Schwabenheinz
  • 133
  • 1
  • 11

2 Answers2

2

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.

Manuel Stör
  • 141
  • 1
  • 4
  • Thank you for your hint! I tried it, but there seems to be an error. 1) I selected the jrxml file. 2) I selected the resource xx.DAO.findALL() 3) I was not able to enter any parameter. 4) In the mapping I had only the Report fields, I had no chance to enter a resource field (doble click, right-click -> nothing worked) 5) Independend from what I selected for Export Type and Resource I got the error message in the dialog "Resource must return a collection" 6) I was not able to click on finish --> it was greyed – Schwabenheinz Aug 17 '20 at 09:39
  • I did it a second time in a new UI-page. Then the wizzard did what exected. But after try running it I got the error: "java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/data/JsonData..... Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.data.JsonData" I will go ahead by checking reason for that. – Schwabenheinz Aug 17 '20 at 10:18
  • I could fix it, by updating the maven dependencys to the latest. Now everything worked fine. – Schwabenheinz Aug 17 '20 at 12:45
0

With help by the answer above I got it running by following code:

            final StreamResource pdf = Report.New()
            .jrxml("/frontend/reports/MyReport.jrxml")
            .dataSource(MyReportDAO.INSTANCE.findAll())
            .mapField("Beschreibung", "beschreibung").mapField("Status", "status")
            .mapField("Erfassungsdatum", "erfassungsdatum").mapField("StatusAenderungsDatum", "statusAenderungsDatum")
            .exportToResource(Format.Pdf());
        
        final HtmlObject pdfViewer = new HtmlObject(pdf, "application/pdf");
        pdfViewer.setSizeFull();
        this.add(pdfViewer);
Schwabenheinz
  • 133
  • 1
  • 11