I hope someone can help me to fix my problem. I am creating a report where it needs to show its child class. Person -> History. This is what i did so far:
if(jComboBox1.getSelectedItem().toString().equalsIgnoreCase("Personal Data Sheet")){
String reference = "";
String name = "";
String homeAddress = "";
String dob = "";
...
if(application != null){
reference = application.getReference();
name = application.getApplicant() != null ? application.getApplicant().getCompleteName() : "";
homeAddress = application.getApplicant() != null
&& !application.getApplicant().getHomeAddress().isEmpty()
? application.getApplicant().getHomeAddress().isEmpty() : "";
...
}
try {
//JRDataSource jrDataSource = new JRBeanCollectionDataSource(datasource);
List<Map<String, Object>> datasource = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("field1", reference);
map.put("field2", name);
map.put("field3", homeAddress);
...
HistoryService hisService = new HistoryServiceImpl();
if(hisService.findHistoryByReference(reference) != null){
for(History his: hisService.findHistoryByReference(reference)){
map.put("hisNam", his.getName());
map.put("hisDesc", his.getDescritpion());
}
}
...
datasource.add(map);
JRDataSource jRDataSource = new JRBeanCollectionDataSource(datasource);
JasperDesign jasperDesign = JRXmlLoader.load(new File("")
.getAbsolutePath() + "/src/org/project120/report/PDSReport.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, jRDataSource);
JasperViewer jasperViewer = new JasperViewer(jasperPrint, false);
jasperViewer.setVisible(true);
...
My problem arises with my for loop. upon viewing the Report generated it only displays the last item on the list. I looked for other solution online and most of it uses subreport but it use with direct connection (query). In my case i am using empty data set.
My desire output is somehing like:
Personal Data Sheet Reference: 12345
Name: Jhon D. Doe
Home Address: Sample Address
Background History(ies):
History 1 This is history 1
History 2 This is history 2
...
Thank you very much in advance for any help