JasperReports: Passing in a list of lists as a datasource

前端 未结 3 622
耶瑟儿~
耶瑟儿~ 2020-12-21 07:03

I need to populate a few subreports with lists of different objects. Basically lets say i have the following:
Subreport on used Vehicles
Subreport on new Vehicles<

相关标签:
3条回答
  • 2020-12-21 07:51

    i was the same problems with you and i solved it using the tag List of jasper, i used datasource in my class java, for example: parameter.put("MyList", new JRBeanCollectionDataSource(ListObjects)); in JRXML

    In palete of Jasper, choose the tag LIST and drag and drop in your relatory after choose

    • create new dataset
    • create new dataset from a connection… ...
    • in data adapter choose new data adapter - collection of javabeans
    • use a JRDatasource expression
    • go in lis of parameters and choose you list op objects (MyList)

    now go to outline of jasper and - dataset properties - edit and query filter ... ... - javabean - search you class (I using eclipse, so it's easy to search my class) - add fields to use

    0 讨论(0)
  • 2020-12-21 07:52

    Selecting your SubReport you can set the property "Connection type" as "Use a data source expression" and inside the property "Data Source Expression" you set this:

    new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{yourFieldHere})
    

    Where your "yourFieldHere" is a list (don't forget to set the "Field Class" inside your field properties as a java.util.List as well)

    0 讨论(0)
  • 2020-12-21 08:05

    Ok, then you need create two fields with the Field Class as java.util.List, one for each list (newVehiclesList and usedVehiclesList).

    Put your two SubReports wherever you want and click on each one doing the following steps:

    Change the "Connection type" to "Use a datasource expression" then change the "Data Source Expression" to new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{yourField})

    Done.

    ps: In order to use the fields inside your newVehiclesList and usedVehiclesList you have to create them inside of their own subReports.

    0 讨论(0)
提交回复
热议问题