Reports addon available?

Does the current JMix release include the Reports addon ?

Hi,

The Reporting add-on is in the phase of testing and stabilitization, and it’s not published yet. It will appear at https://www.jmix.io/marketplace when it’s ready.

1 Like

I’ve done the job with jasper reports and call the report with jasper class directly
Suppose you have the jasper report file called “report”, add the xml definition to resources folder in a file called “report.jrxml”.

Put the code in a java class for the report generation

@RestController
@Service
public class ReportCustomerService {

@Autowired
@Secure
private DataManager dataManager;
protected JasperPrint jasperPrint;

public void exportReport() throws JRException, IOException {

    List<Customer> customerlist = dataManager.load(Customer.class)
                        .query("select e from customer e ")
                        .list();

    ClassLoader classLoader = getClass().getClassLoader();
    InputStream url = null;
    url = classLoader.getResourceAsStream("report.jrxml");
    JasperReport jasperReport = JasperCompileManager.compileReport(url);
    JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(customerlist);
    Map<String, Object> parameters =new HashMap<>();
    parameters.put("createdBy","You");
    this.jasperPrint = JasperFillManager.fillReport(jasperReport,parameters,dataSource);
    return ;

}

@RequestMapping(value = "/report", method = RequestMethod.GET,produces = MediaType.APPLICATION_PDF_VALUE)
public ResponseEntity<InputStreamResource> getDocument() throws JRException {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    JasperExportManager.exportReportToPdfStream(this.jasperPrint, out);;
    ByteArrayInputStream bis = new ByteArrayInputStream(out.toByteArray());


    HttpHeaders headers = new HttpHeaders();
    headers.add("Content-Disposition", "inline; filename=report.pdf");

    return ResponseEntity
            .ok()
            .headers(headers)
            .contentType(MediaType.APPLICATION_PDF)
            .body(new InputStreamResource(bis));

}

}

Then call the report from your form

inject the ReportCustomerService class in the controller
@Autowired
private ReportCustomerService reportCustomerService;

@Subscribe("btnGenerateReport")
public void onBtnGenerateReportClick(Button.ClickEvent event) throws JRException, IOException {

    reportCustomerService.exportReport();
    webBrowserTools.showWebPage("/report", ParamsMap.of("_target", "blank"));

}