Problem sending list of datasource to sub reports

1

I'm having trouble opening a report with sub reports passing a datasource.

In Ireport I run the report with sub reports normally, but the main report has a connection to the database and this connection is passed to the sub reports and each report has its query in the database.

This raises a question: when a report list is passed to the SQL query in the report is it unnecessary?

The application to call the report passes a datasource only that only the main report receives the data from the list and does not pass it on to the sub reports.

ex: in the main report has a field location then I choose this item in the list, the next sub report has a provider field so the list coming from the main report is received and I choose the item vendor name and in the other sub report has the move with most of the mass of data in the list where the columns are filled.

In the properties of the sub report in Connection type I have to put: Use the datasource expression and in Connection expression: '' new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource (list) "'.

The examples I find show the list in a report field. And in my case I want the list to arrive in sub reports and each list item fills in a report field.

Here is the layout image of how I'm doing the report: the main one brings the localities the middle one brings the suppliers from that locality and the last one brings the movement according to the supplier and the locality.

I tried to do this in just one report with Groups but I could not get it to bring all vendors in a location and all related vendor and locale moves. Anyone who has any idea how to call the report with is in the figure by the System I thank you. Just a detail the system is WEB JSF + JPA + Hibernate.

    
asked by anonymous 14.10.2014 / 21:24

1 answer

1

If there is not a very large amount of data, so there is no difficulty in storing the entire list in memory, you can pass any collection of objects to the report through JRBeanCollectionDataSource .

Since you already have the data, the report does not need to perform any queries. The fields used in the report are the attributes of the objects contained in the list.

To create sub-reports in this way, have the main list objects have an attribute that returns another list and passes that list to the sub reports.

For example, if you have this:

public class Fornecedor {
    private String contrato;
    ...
}
public class Localidade {
    private String descricao;
    public List<Fornecedor> fornecedores;
    ...
}

First, pass the list of locations to the main report, then specify as DataSource of the subreport the following:

 new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{fornecedores})
    
14.10.2014 / 22:38