Jump to content
We've recently updated our Privacy Statement, available here ×

How to combine main and subreport, both based on different csv


jeroeng

Recommended Posts

Hi all,

I have the requirement to build a report with several subreports which are all based on .csv files. All reports (main and sub's) are working individually as required, but I can't manage to work the sub reports into the main report.

Sources:

  • customer.csv  => contains customer name and some more information. 
    • name, address, billing info
  • server.csv      => contains customer name, server IP and more information. 
    • fqdn, ip, customer, type, purpose

My master report is based on the customer.csv and reports name of all customers in the file. Below each customer name I want to see all servers we manage for this customer, so customers Name is the linking field.

Customer-1
server-1   10.10.10.1
server-2  10.10.10.2

Customer-2
server-a   192.168.1.1
server-b   192.168.1.2

Steps I took creating the subreport in the main report:

  1. Field name (= customer name) is in the "Detail 1" band of the main report.
  2. Drag the subreport element in the "Detail 2" band of the main report
    1. Select the correct subreport (Server.jxml) which converts automatically to "Server.jasper"
    2. Select no datasource
    3. Edit the parameters to have the field Name from the main report be put in parameter Customer in the subreport ($F{Name}
  3. Select the subreport and modify the properties:
    1. Data Source Expression set to the location of the server.csv ("C:\Users\jeroen_g\xxxxx\Assets_report\server.csv"

Running the master report in preview gives the following error:

net.sf.jasperreports.engine.JRException: java.lang.ClassCastException: class java.lang.String cannot be cast to class net.sf.jasperreports.engine.JRDataSource (java.lang.String is in module java.base of loader 'bootstrap'; net.sf.jasperreports.engine.JRDataSource is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @484b5a21)    at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport(ReportController.java:551)    at com.jaspersoft.studio.editor.preview.view.control.ReportController.access$18(ReportController.java:526)    at com.jaspersoft.studio.editor.preview.view.control.ReportController$1.run(ReportController.java:444)    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class net.sf.jasperreports.engine.JRDataSource (java.lang.String is in module java.base of loader 'bootstrap'; net.sf.jasperreports.engine.JRDataSource is in unnamed module of loader org.eclipse.osgi.internal.loader.EquinoxClassLoader @484b5a21)    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:529)    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:357)    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:383)    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:548)    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2600)    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:825)    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:266)    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:110)    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:621)    at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFill.run(BaseFillHandle.java:135)    at java.base/java.lang.Thread.run(Unknown Source)

Most likely I'm just missing a small piece here, but have been googling and experimenting for almost a day without success. Hope somebody can direct me in the correct way.

Thanks,

Jeroen

 

 

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

I believe the issue you are facing is due to this step: 

  1. Data Source Expression set to the location of the server.csv ("C:\Users\jeroen_g\xxxxx\Assets_report\server.csv"

What you need to do is ensure that your subreport is pointing to the correct data adapter (in Studio). You do not need to populate the Data Source Expression field in the main report unless you are passing data "thru" to the subreport.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...