Jump to content
Changes to the Jaspersoft community edition download ×

XML connection in subreport in Java


essaghir.bouchra

Recommended Posts

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!");
 
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...