Problem sending datasource list to sub reports

Asked

Viewed 618 times

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 is with a connection to the database and this connection is passed to sub reports and each of the reports has its query in the database.

This begs a doubt: when a list is passed to the report the SQL query in the report is 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 to the sub reports.

ex: in the main report has a locale field so I choose this item in the list, in the next sub report has a vendor field so the list coming from the main report is received and I choose the itemName item and in the other sub report have the movement with most of the data mass of the list where the columns are populated.

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 arrow the list in a report field. And in my case I want the list to reach the sub reports and each item in the list to fill a field in the report.

It follows the layout image of how I am doing the report: the main brings the localities the middle brings the suppliers of that locality and the latter brings the movement according to the supplier and the locality.

Relatório

I also tried to do this in just one report with Groups but I could not get it to bring all suppliers from a locality and all related movements co supplier and locality. Anyone who has any idea how to call the report as is in the picture by the System I thank. Only one detail the system is WEB JSF + JPA + Hibernate.

1 answer

1

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

As you already have the data, the report does not need to execute any query. The Fields used in the report are the attributes of the objects contained in the list.

To create sub-reports this way, make the main list objects have an attribute that returns another list and passes that list to 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 how DataSource of the sub-report the following:

 new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{fornecedores})
  • The list passed is from the movement table that has relationships with several tables N:1 as: service, location and contract and this has relationship with supplier. And this list is filtered by the user by an initial date and an end date. In the figure I posted in Ireport the 1st report search all suppliers of a locality in the 2nd search all movement of a locality and the 3rd search the movement itself. When running in Ireport brings the data all grouped as in the figure but is done by a connection to the database.

  • The problem is to do this in the application that sends a list that are the report completion data. The list Is not an attribute of any class, but will send all data to complete the report.

  • Main report receives data from the list but sub reports do not.

  • @user17132 You cannot create the classes in the necessary structure and do a pre-processing of the data so that it stays in the structure that best suits the report?

  • utluiz, do not understand. give to explain better?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.