项目作者: alejandro-du

项目描述 :
Generate Jasper Reports from your entities/beans/POJOs.
高级语言: Java
项目地址: git://github.com/alejandro-du/report-ui.git
创建时间: 2017-12-13T20:24:44Z
项目社区:https://github.com/alejandro-du/report-ui

开源协议:Apache License 2.0

下载


Published on Vaadin  Directory
Stars on Vaadin Directory
Latest version on vaadin.com/directory

Report UI Add-on provides an easy way to render JasperReports in Vaadin applications through DynamicJasper.

Basic usage

Say, you have the following domain/entity/Java Bean class:

  1. public class Call {
  2. private Long id;
  3. private String client;
  4. private String phoneNumber;
  5. private City city; // enum
  6. private LocalDateTime startTime;
  7. private Integer duration;
  8. private Status status; // enum
  9. ... getters and setters ...
  10. }

You can create a new report and add it to any Vaadin layout as follows:

  1. PrintPreviewReport<Call> report = new PrintPreviewReport<>(Call.class);
  2. report.setItems(Repository.findAll());
  3. layout.addComponent(report);

Advanced usage

You can optionally set the order of the columns as follows:

  1. PrintPreviewReport<Call> report = new PrintPreviewReport<>(Call.class, "client", "city", "phoneNumber", "startTime", "duration", "status");

If you prefer, you can use the default constructor to avoid creating the columns automatically. In that case, you can use the getReportBuilder() method to set the columns manually:

  1. PrintPreviewReport<Call> report = new PrintPreviewReport<>();
  2. report.getReportBuilder()
  3. .setMargins(20, 20, 40, 40)
  4. .setTitle("Call report")
  5. .addAutoText("For internal use only", AutoText.POSITION_HEADER, AutoText.ALIGMENT_LEFT, 200, headerStyle)
  6. .addAutoText(LocalDateTime.now().toString(), AutoText.POSITION_HEADER, AutoText.ALIGNMENT_RIGHT, 200, headerStyle)
  7. .addAutoText(AutoText.AUTOTEXT_PAGE_X_OF_Y, AutoText.POSITION_HEADER, AutoText.ALIGNMENT_RIGHT, 200, 10, headerStyle)
  8. .setPrintBackgroundOnOddRows(true)
  9. .addColumn(city = ColumnBuilder.getNew()
  10. .setColumnProperty("city", City.class)
  11. .setTitle("City")
  12. .build())
  13. .addGroup(new GroupBuilder()
  14. .setCriteriaColumn((PropertyColumn) city)
  15. .build())
  16. .addColumn(ColumnBuilder.getNew()
  17. .setColumnProperty("client", String.class)
  18. .setTitle("Client")
  19. .build())
  20. .addColumn(ColumnBuilder.getNew()
  21. .setColumnProperty("phoneNumber", String.class)
  22. .setTitle("Phone number")
  23. .build())
  24. .addColumn(ColumnBuilder.getNew()
  25. .setColumnProperty("startTime", LocalDateTime.class)
  26. .setTitle("Date")
  27. .setTextFormatter(DateTimeFormatter.ISO_DATE.toFormat())
  28. .build())
  29. .addColumn(ColumnBuilder.getNew()
  30. .setColumnProperty("startTime", LocalDateTime.class)
  31. .setTextFormatter(DateTimeFormatter.ISO_LOCAL_TIME.toFormat())
  32. .setTitle("Start time")
  33. .build())
  34. .addColumn(ColumnBuilder.getNew()
  35. .setColumnProperty("duration", Integer.class)
  36. .setTitle("Duration (seconds)")
  37. .build())
  38. .addColumn(ColumnBuilder.getNew()
  39. .setColumnProperty("status", Status.class)
  40. .setTitle("Status").build());

See the DynamicJasper documentation for more configuration examples.

You can get a StreamResource for downloading the report in various formats. For example:

  1. StreamResource streamResource = report.getStreamResource(
  2. "report.pdf", itemsSupplier, PrintPreviewReport.Format.PDF);
  3. Anchor pdf = new Anchor(streamResource, "Download PDF");

Apache POI is required when using some of the exporting methods:

  1. <dependency>
  2. <groupId>org.apache.poi</groupId>
  3. <artifactId>poi-ooxml</artifactId>
  4. <version>3.10-FINAL</version>
  5. </dependency>

In order to render charts you have to configure an ImageServlet. For example:

  1. @WebServlet("/report-image")
  2. public static class ReportsImageServlet extends ImageServlet {
  3. }

You can configure the URL pattern using the setImageServletPathPattern method (default to report-image?image={0}).