Search code examples
javajasper-reports

how to execute jasper reports sub report with hashmap variable?


trying to make sub report with the next code:

int SelectedVoucher=Integer.valueOf(VNumber_ID_lbl.getText());
try {
    Connect c=new Connect();
    HashMap map = new HashMap();
    map.put("Voucher_ID", SelectedVoucher);
    String PaymentReport="src\\voucherexpress\\VoucherReport.jrxml";
    String SubPaymentReport="src\\voucherexpress\\VoucherReport_subreport1.jrxml";               
    JasperReport jasperMasterReport = JasperCompileManager.compileReport(PaymentReport);
    JasperReport jasperSubReport = JasperCompileManager.compileReport(SubPaymentReport);

    JasperPrint jasp_print=JasperFillManager.fillReport(jasperMasterReport, map,c.Connstr);
    JasperViewer.viewReport(jasp_print);
    c.Connstr.close();

} catch (JRException | SQLException | IOException ex) {
    JOptionPane.showMessageDialog(null, ex);
}

I added sub report to main report, Create new query,test it and it's runnin well . Both of reports using the same parameter (Voucher_ID) but when I execute it with the main report , it shows the main report data only and the sub query is empty. how can i run the sub report inside the main report


Solution

  • I've solved the issue:
    first : there is no use of this rows :

    String SubPaymentReport="src\\voucherexpress\\VoucherReport_subreport1.jrxml";  
    JasperReport jasperSubReport = JasperCompileManager.compileReport(SubPaymentReport);
    

    second: in main report design page , click on sub report and chose parameters from properties , add the same parameter of the main report >>> and done , it's work