Display JavaBean List Data with JRBeanCollectionDataSource

If you are working with JavaBeans and want to display data from a list of those beans in a JasperReports report, you can use the JRBeanCollectionDataSource class to easily create a data source for your report.

The first step is to create a list of your JavaBeans that you want to display in the report. Let's say you have a JavaBean class called Person with properties such as name, age, and address.

<pre>
public class Person {
  private String name;
  private int age;
  private String address;

  // getters and setters
}
</pre>

Now, you can create a list of Person objects and populate it with data:

<pre>
List<Person> personList = new ArrayList<>();
personList.add(new Person("John Doe", 30, "123 Main St."));
personList.add(new Person("Jane Smith", 25, "456 Oak Ave."));
// add more Person objects as needed
</pre>

Next, you can create a JRBeanCollectionDataSource object from the list of Person objects:

<pre>
JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(personList);
</pre>

Finally, you can pass the dataSource object as the data source for your JasperReport:

<pre>
JasperPrint print = JasperFillManager.fillReport(report, parameters, dataSource);
</pre>

With this approach, you can easily display data from a list of JavaBeans in your JasperReports report.

Click to rate this post!
[Total: 0 Average: 0]

Related posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Go up

Below we inform you of the use we make of the data we collect while browsing our pages. You can change your preferences at any time by accessing the link to the Privacy Area that you will find at the bottom of our main page. More Information