Home >Java >javaTutorial >How to Display a JavaBean\'s List in JasperReports\' Detail Band?
A JavaBean contains a java.util.List. How can this list's data be displayed in the Detail band of a JasperReports document?
// Java source to generate the report ... // DataSource using JRBeanCollectionDataSource private static JRDataSource getDataSource() { Collection<beanwithlist> coll = ...; return new JRBeanCollectionDataSource(coll); } // JavaBean public class BeanWithList { private List<string> cities; // ... // Ensure a public getter for field extraction public List<string> getCities() { return this.cities; } } // jrxml file ... // Subdataset for iterating through the list <subdataset name="dataset1"> <field name="city" class="java.lang.String"> <fielddescription></fielddescription> </field> </subdataset> // Detail band with jr:list component <detail> ... <componentelement> <!-- jr:list component --> <list ...> <datasetrun subdataset="dataset1"> <!-- DataSource expression using JRBeanCollectionDataSource --> <datasourceexpression></datasourceexpression> </datasetrun> <listcontents ...> <textfield ...> <textfieldexpression></textfieldexpression> </textfield> </listcontents> </list> </componentelement> ... </detail> ...</string></string></beanwithlist>
This configuration generates a report displaying the list's data within the Detail band.
Other relevant questions address this topic:
The above is the detailed content of How to Display a JavaBean\'s List in JasperReports\' Detail Band?. For more information, please follow other related articles on the PHP Chinese website!