Calling Subreport in Main Report

Asked

Viewed 4,217 times

3

Guys, I have 2 reports, the sub report and the main report, but when I give a preview I can only view the main one, as I do to display the sub report as well?

I’m using Jaspersoft Studio.


I have a report that is filled by a list and parameters, but I found a problem and I received help here in the forum, the person who helped me said that the best way to solve this problem is by creating a Subreport. The problem is this, I want to leave my report as follows: inserir a descrição da imagem aqui

As you can see, a Beneficiary has more than one procedure. Currently I can list all the procedures and beneficiaries, but the procedures repeat. This is what I currently get: inserir a descrição da imagem aqui

My Beneficiary Name repeats, and shows the other procedure, not all together in one place.

I am trying to place a Subreport with the Payee Name and Identifier in a Group Header, and the procedures (Date Completion, Service Description, Cod Tab..) within Detail. I think that way it would work, but I’m not able to call the Subreport within my report.

  • 1

    Secondary report needs to be compiled in a file .jasper in some specific directory. And then in the subreport component in the main report you need to specify a path to the compiled subreport file. If you need more help, click [Edit] on your question and add more information about your report. Hug!

  • I understood, but how do I step this way, what kind of parameter?

  • edited the question

  • Take a look here.

  • I have looked but not understood, there it passes an ID as parameter and I suppose it is by connection JDBC, using lists as data source works the same way?

  • Diego, can you give me your report for me to use as a model ?

  • @Fillipedeveloper of ours, I no longer have access to it a long time hehe.

Show 2 more comments

1 answer

1


You need to specify the path to the subreport from within the main report.

This should be done in the subreport component, in its attribute Subreport Expression, as shown below:

Definir propriedades do subrelatório

There you can specify the path to the file .jasper of the sub-report through one of the types String, File, InputStream, URL and JaspeReports.

  • I did this but still does not load the Subreport, I have to configure something in the Subreport?

  • It looks like this: http://i.stack.Imgur.com/Ezpcv.png

  • @Diegoaugusto No errors in tab Output?

  • No, I don’t think it’s being displayed by returning everything null, I’ll try to call by code by Imputstream

  • @Diegoaugusto It may be that you are not displaying anything because of the lack of data. Are you passing the parameters to the subreport? Try putting a fixed query and see if something appears.

  • I am trying to pass a list, there is the difficulty. I tried to pass the sub report as parameter and gave this error: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
 Source text : $P{sub}

  • @Diegoaugusto Check if the type of ${sub] is compatible with the type reported in the other field that informs the type. For example, if it is a String, it must be java.lang.String.

  • I was sending by Inputstream as follows: InputStream sub= this.getClass().getResourceAsStream("/br/com/xml/relatorio/subRelatorio.jrxml");

  • And then wore filtro.put("sub", sub);

  • But I think you’re making a mistake because I’m trying to pass a list to the sub-report and I don’t know if I’m doing it right. Summing up I need to pass a list to the main report, this I can already do, now I need to pass a list to the sub report and then call my main report with the sub report inside.

Show 5 more comments

Browser other questions tagged

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