I try to use Jaspersoft iReport to create Report from my POJO and export it to PDF.
My POJO looks like this:
class Topic {
String topicName
int topicPoints;
DateRange dateRange;
List<Post> posts;
}
class DateRange {
LocalDate begin;
LocalDate end;
}
class Post {
String postName;
int postPoints;
}
I found solution with JRBeanCollectionDataSource, so I created list with one element (my POJO).
ArrayList<Topic> list = new ArrayList<>();
list.add(topic);
JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(list);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, beanColDataSource);
JasperExportManager.exportReportToPdfFile(jasperPrint, "C:/jasper/test.pdf");
I have no problems with exporing simple data like Strings, Integers etc.
e.g. this exports fine.
class Topic {
String topicName
Integer topicPoints;
}
With just:
Drag & Drop fields topicName (with "java.lang.String"
) and topicPoints
(with "java.lang.Integer"
)
But how can I put on my reports nested fields inside dateRange or inside posts?
I see there is field class like java.lang.Object
or java.util.List
, but how can I define fields inside this Object or List?
My ideal solution would've create report like:
UPDATE:
class Topic {
String topicName
int topicPoints;
DateRange dateRange;
List<Post> posts;
}
class DateRange {
LocalDate begin;
LocalDate end;
}
class Post {
String postName;
int postPoints;
List<User> users;
}
class User {
String userName;
int userPoints;
}
And what in case when it will be even more nested?