java - How to dynamically add multiple pieces of data in Jasper Reports -


I have a report on Java that I am working in Java.

In Java, I can dynamically populate a bean with the data with the following code:

  list & gt; ThemeBean & gt; Theme = New Arreelist & gt; ThemeBean & gt; (); CSVReader csvReader = new CSVReader (new FileReader (csvFilename)); & Lt; String [] & gt; Data = csvReader.readAll (); (String [] D: data) {Themebeam TB = new themeben (); Tb.setThemes (d [0]); Tb.setComments (d [1]); Tb.setSentiment (d [2]); Themes.add (TB); } Jasper Design jasperDesign = JRXmlLoader.load (fileName); JRBeanCollectionDataSource DS = new JRBeanCollectionDataSource (themes); JasperReport jasperReport = JasperCompileManager.compileReport (Jasper Design); JasperPrint jasperPrint = JasperFillManager.fillReport (Jasperport, Blank, DS);   

This works fine when the correct fields in the .jrxml file are specified and the textFieldExpression is within the tag ...

The following dynamically generated list was made:

  & lt; TextFieldExpression & gt; & Lt ;! [CDATA [$ F {subjects}]] & gt; & Lt; / TextFieldExpression & gt;   

My problem is that how to do it dynamically for two different tables in the same report. It seems that I dynamically add only data I can use a frequency. I am trying to get a result where I have two completely different tables generated within the same report. If this question is not clear, please tell me and I will try to fix it. Thank you. By creating another bean with a bean collection you can pass more than one bean collection in the report.

This bean will look like this:

  public class databen {personal Collection beanCollection = null; Public DataBen () {} Public Collection getBeanCollection () {Return beanCollection; } Public Zero Setbean Collection (collection beaconicization) {this.beanCollection = beanCollection; }}   

I think the second collection will be different from ThemeBean . I am using Falben as an example for every bean collection you want to pass, you create a DataBean and add it to the collection, then If passing that collection to the report, then your code will change something like this: List & gt; DataBean & gt; AllData = new ArrayList & lt; DataBean & gt; (); // ... to prepare and populate the list & lt; ThemeBean & gt; Theme 'Databan DB = New DataBen (); Db.setBeanCollection (topics); AllData.add (database); // ... ready and populate 'list & lt; Freiben & gt; Fruit`db = new databen (); Db.setBeanCollection (fruit); AllData.add (database); // ... Load the report JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource (allData); // ... fill out the report

The report filling this data source will be a shell report, which will have a subreport for each DataBean . Only one field will be available in this report: $ F {beanCollection}

Data source expression for sub-location (s) set to

JRBeanCollectionDataSource ($ F {beanCollection}) .

FieldBean or FruitBan fields will be available in sub-support.

If you prefer to use the list component instead of sub-reports, whatever works.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -