简体   繁体   English

表字段的JsonDataSource获取空的Jasper报告

[英]JsonDataSource for table fields get empty Jasper report

I am new to jasper reports. 我是初学者报告的新手。 I am trying to generate a pdf from a son file, which contains some info like name , class etc and an array marks . 我正在尝试从一个子文件生成一个pdf文件,其中包含一些信息,例如nameclass等和一个数组marks I am trying to render the marks array as a table. 我试图将标记数组呈现为表。 my JSON is 我的JSON是

{"data": {"name" : "Johny",
    "class" : "A2",
    "sub" : "cs",
    "interest" : "films",
    "marks" : [{
               "subject" : "Maths",
               "mark" : "24",
               "grade" : "A",
               "remarks" : "",
               "slNo" : "1"
               },
               {
               "subject" : "English",
               "mark" : "24",
               "grade" : "A",
               "remarks" : "",
               "slNo" : "2"
               },

               ]
}}

I have given subdatasource expression as 我给了子数据源表达式为

<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource()]]></dataSourceExpression>

Full jrxml - Here 完整的jrxml- 在这里

Now I call these from java like, 现在我从java调用这些,

File jsonFile = new File("/Volumes/Johny/Work/EclipseWorkspace/SecondReport/res/Marks.Json");
JasperDesign jasperDesign = JRXmlLoader.load(new File("/Volumes/Johny/Work/EclipseWorkspace/SecondReport/res/First.jrxml"));
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

parameters.put(JsonQueryExecuterFactory.JSON_INPUT_STREAM, new FileInputStream(jsonFile));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters);
JasperExportManager.exportReportToPdfFile(jasperPrint, "/Users/johnykutty/Desktop/Sample2.pdf");

Other fields are getting populated, but table values are getting as null. 其他字段正在填充,但表值却为null。

Found answer from here The issue was I have to pass the key for the array in dataSourceExpression . 这里找到答案问题是我必须在dataSourceExpression传递数组的键。 So, the dataSourceExpression should be like 因此, dataSourceExpression应该像

<dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("marks")]]></dataSourceExpression>

Note the "marks" parameter to subDataSource() method 注意subDataSource()方法的“ marks”参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM