XML connection in subreport in Java

0

Hello,

I'm writing a java program which is supposed to generate a jasperreport. It uses subreports who have different XPath and when I try to generate it, the contents of the subreport doesn't display and I'm guessing it's because of XML connection to the subreports. I tried to pass the JasperReport as parameter but it didn't work..

So, my question would be how to add the XPath to the subreport and then pass it to the main report ?

Thank you, here is my java code: 

 File xmlDataSourceFile = new File ("C:/Users/bessaghi/Documents/Jasper/AirbusDataForReport.xml");
  JRXmlDataSource xmlDataSourceXPath_mainReport = new JRXmlDataSource (xmlDataSourceFile, "/request");
  JRXmlDataSource xmlDataSourceXPath_subReport_ElectronicDistributionList = new JRXmlDataSource (xmlDataSourceFile, "/request/distributionlist/actor");
  
  /* Compile the template */
  JasperReport jasperMainReport = JasperCompileManager.compileReport ("C:/Users/bessaghi/Documents/Jasper/reportNewForm.jrxml");
  JasperReport jaspersubReport_ElectronicDistributionList = JasperCompileManager.compileReport ("C:/Users/bessaghi/Documents/Jasper/reportNewForm_subreportElectronicDistributionList.jrxml");
  JasperPrint  jasperCompiledsubReport_ElectronicDistributionList = JasperFillManager.fillReport (jaspersubReport_ElectronicDistributionList, new HashMap (), xmlDataSourceXPath_subReport_ElectronicDistributionList);
  
  JasperExportManager.exportReportToHtmlFile(jasperCompiledsubReport_ElectronicDistributionList, "C:/Users/bessaghi/Documents/Jasper/subReport_ElectronicDistributionList.html");
  
  HashMap parameters = new HashMap ();
  parameters.put("imageAirbusPath", "C:/Users/bessaghi/JaspersoftWorkspace/MyReports/GTN/Airbus.JPG");
  parameters.put("imagesPath", "C:/Users/bessaghi/Documents/Jasper/images/");
 
  /* Create the JasperPrint object with the template and the data */
  JasperPrint  jasperCompiledReport = JasperFillManager.fillReport (jasperMainReport, parameters, xmlDataSourceXPath_mainReport);
     
  /* Export the report to pdf format if needed*/
  JasperExportManager.exportReportToHtmlFile(jasperCompiledReport, "C:/Users/bessaghi/Documents/Jasper/MyReport.html");
  
  System.out.println("Done!");
 
essaghir.bouchra's picture
Joined: Jun 2 2017 - 2:32am
Last seen: 2 years 3 days ago

0 Answers:

No answers yet
Feedback