Creating/Passing Java bean Datasource in JasperReport

后端 未结 1 1005
醉话见心
醉话见心 2020-12-30 09:16

I am using JasperReport and ireport in my JSF application to generate reports on the fly. This is what I am trying to achieve:-

  1. My structure(read as HashMap

相关标签:
1条回答
  • 2020-12-30 09:53

    If you already have a DataSource then you can pass your List/Map thourgh the param Map when you're filling your report.

    Map<String, Object> param = new HashMap<String, Object>();
    param.put("SUB_DATA_SOURCE", yourList);
    
    JasperFillManager.fillReport(jasperReport, param,
                    new JRBeanCollectionDataSource(yourMainListHere));
    

    Doing that you have to create a parameter inside your MAIN report with the same name you have set in your param Map and also give to this a Type Class (List in my case).

    Than you have to create your subreport element and set the Connection Type as "Use a datasource expression" and inside the "Data Source Expression" you set this:

    new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{SUB_DATA_SOURCE})
    
    0 讨论(0)
提交回复
热议问题