使用两个不同的Java bean填充单个报表

时间:2017-01-18 17:11:36

标签: java jasper-reports javabeans

我是jasper报告的新手,并且我尝试使用两个不同的java bean填充单个报告,我的报告有两个不同的部分一个用于患者信息,另一个用于药物,我创建了两个不同的bean,一个用于药物,另一个用于患者信息,从我的post_save类我有两个方法返回每个bean的bean列表。

我得到了beanFactory

这是编译和填充碧玉报告的代码:

java.lang.NoSuchMethodException: Unknown property 'med' on class 'class jasperreport.Bean'

这些是我的两个豆子: 的 medBean

public class or {

    public or(){

        try {
            InputStream stream= new FileInputStream("ordonanceReport.jrxml");


            JasperReport MasterReport = JasperCompileManager.compileReport(stream);


            Map<String, Object> parameters = new HashMap();
            parameters.put("ReportDataSource", new JRBeanCollectionDataSource(BeanFactory.getMedBeans()));

            JasperPrint print= JasperFillManager.fillReport(MasterReport, parameters
                ,new JRBeanCollectionDataSource(BeanFactory.getInfoBeans()));
            JasperViewer.viewReport(print);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    public static void main(String[] args) {
        or o= new or();
    }  
}

InfoBean

public class medBean {
    private String med="";

    public medBean(String med) {
        super();
        this.med = med;
    }

    public String getMed() {
        return med;
    }

    public void setMed(String med) {
        this.med = med;
    }


}

这是bean工厂类: 的的BeanFactory

public class InfoBean {

    private String date="";
    private String nomPatient="";
    private String prenomPatient="";
    private String agePatient="";



    public InfoBean(String date, String nomPatient, String prenomPatient, String agePatient) {
        super();
        this.date = date;
        this.nomPatient = nomPatient;
        this.prenomPatient = prenomPatient;
        this.agePatient = agePatient;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getNomPatient() {
        return nomPatient;
    }

    public void setNomPatient(String nomPatient) {
        this.nomPatient = nomPatient;
    }

    public String getPrenomPatient() {
        return prenomPatient;
    }

    public void setPrenomPatient(String prenomPatient) {
        this.prenomPatient = prenomPatient;
    }

    public String getAgePatient() {
        return agePatient;
    }

    public void setAgePatient(String agePatient) {
        this.agePatient = agePatient;
    }

}

我已将此行添加到我的jasperreport文件中,以便能够获取medBean:

public class BeanFactory {
    public static Collection getInfoBeans(){
        List<Bean> allbeans = new ArrayList<>();
        try { 

            allbeans.add(new Bean("12/01","gherbi","mohamed","22"));
            allbeans.add(new Bean("13/33","gherbi","Hicham","27"));
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return allbeans;
    }
    public static Collection getMedBeans(){
        List<medBean> allbeans = new ArrayList<>();
        try { 

            allbeans.add(new medBean("12/0dgddghd"));
            allbeans.add(new medBean("13/3bdhhsdhd"));
        }
        catch(Exception e){
            e.printStackTrace();
        }
        return allbeans;
    }

}

这是我的Jasper报告.jrxml文件:

<parameter name="ReportDataSource" class="net.sf.jasperreports.engine.JRDataSource"/>

我觉得我的假设出现了问题,这样做是否有效或者我需要改变什么? PS:我不想使用子报告,我知道这是可能的,我想使用包含所有内容的单个报告。

0 个答案:

没有答案