JasperReport:JRException:从bean中检索字段值时出错(嵌套Bean问题)

时间:2014-01-28 06:25:35

标签: java jasper-reports javabeans

我是jasper报道的新手,我有两个bean,一个是main,另一个是sub bean,我将子bean列表传递给main bean,并从main bean中获取包含子bean列表和两个属性学院的值和地址字段,因为我正在上大学并从主bean正确地解决但是从子bean列表中获取值时出现错误。

错误:

net.sf.jasperreports.engine.JRException: Error retrieving field value from bean : age
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getBeanProperty(JRAbstractBeanDataSource.java:123)
at net.sf.jasperreports.engine.data.JRAbstractBeanDataSource.getFieldValue(JRAbstractBeanDataSource.java:96)
at net.sf.jasperreports.engine.data.JRBeanCollectionDataSource.getFieldValue(JRBeanCollectionDataSource.java:100)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1356)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1257)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1233)
at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1577)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:149)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:932)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:864)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:114)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:653)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:969)

我的代码:

List<StudentTransactionDTO> studentTransactionDTOList = firstDTO.getStudentTransactionDTOList();
firstDTO.setStudentTransactionDTOList(studentTransactionDTOList);
reports.add((Object) firstDTO);
//when i print this on console it prints

jasperDesign = JRXmlLoader.load(getReportFile());
jasperReport = JasperCompileManager.compileReport(jasperDesign);
//It load and compile report successfully.
//It gives error while filling data.
jasperPrint = JasperFillManager.fillReport(jasperReport, parameter,
                    new JRBeanCollectionDataSource(reports,false));

我的第一个豆:

public class FirstDTO {
private String College= "";
private String address= "";
private List<StudentTransactionDTO> studentTransactionDTOList =
new ArrayList<StudentTransactionDTO>();
getter and setters....

Second Bean(Inner Bean):

public class studentTransactionDTO {
private String age= "";
private String Name = "";
private String marks = "";
getter and setters....

请给我一些建议,如何从第二个bean中检索值并设置为jasper报告。

问候。

1 个答案:

答案 0 :(得分:0)

为此,我使用了子报告并在子报告中使用了第二个bean,对于这个答案我得到了帮助:Click Here