如何在Jasper Report中显示子类通行证?

时间:2018-11-22 22:54:01

标签: java jasper-reports subreport

我希望有人可以帮助我解决问题。我正在创建一个需要显示其子班级的报告。 人员->历史记录。这是我到目前为止所做的:

            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);
                ...

我的问题出现在我的 for循环上。查看生成的报告时,它仅显示列表中的最后一项。我在网上寻找其他解决方案,其中大多数使用子报表,但它与直接连接(查询)一起使用。就我而言,我使用的是空数据集

我的愿望输出是这样的:

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
     ...

非常感谢您的帮助

0 个答案:

没有答案