我想在确定没有显示数据的原因时寻求一些帮助。
当我调试代码时, JsonDataSource 包含来自 JSON 文件的值。
在 iReport 上,值在参数和数据字段上都正确显示,但是当通过以下代码运行时,仅显示参数字段。
以下是我正在使用的代码段。
public ActionForward createReport(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String sReportType = (String) request.getParameter("srt");
String sRepType = "";
String sDateFrom = (String) request.getParameter("sdf");
String sDateTo = (String) request.getParameter("sdt");
String sBID = (String) request.getParameter("ddid");
Collection clCol = null;
JSONSerializer serializer = new JSONSerializer();
clCol = dUtil.getInfo(sBID, 1, sDateTo);
String sJsonString = this.convertToJson(clCol, serializer);
Map params = new HashMap();
params.put(JsonQueryExecuterFactory.JSON_DATE_PATTERN, "MM/dd/yyyy");
params.put(JsonQueryExecuterFactory.JSON_NUMBER_PATTERN, "#,##0.##");
params.put(JsonQueryExecuterFactory.JSON_LOCALE, Locale.ENGLISH);
params.put(JRParameter.REPORT_LOCALE, Locale.US);
params.put("bid", dUtil.getNameById(sBID));
params.put("datefrom", sDateFrom);
params.put("dateto", sDateTo);
params.put("reportby", sFullName);
String sFPath = pReader.getPropValue(pReader.REPOJSONDIR);
String sFileNm = pReader.getPropValue(pReader.REPOJSONFILENAME);
String sRepName = dUtil.getReportFileName(sReportType);
sRepType = pReader.getPropValue(pReader.GETREPORTMPLT) + sRepName;
String sFileName = sFPath + sSID.substring(0, 5) + sFileNm;
String sFilePDF = pReader.getPropValue(pReader.GETREPORTMPLTOUT)
+ sSID.substring(0, 5)
+ sRepName.substring(0, sRepName.indexOf("."))
+ ".pdf";
//byte[] bytes = null;
JasperPrint jasperPrint = null;
//ServletOutputStream servletOutputStream = response.getOutputStream();
InputStream reportStream = getClass().getResourceAsStream(sRepType);
// Block for JSON File creation
try {
FileWriter fw = new FileWriter(new File(sFileName));
fw.write(sJsonString);
fw.flush();
fw.close();
} catch (FileNotFoundException fex) {
logMe.setLogError(sUser, sSID, fex.getLocalizedMessage());
}
//End Block
//Block for JasperReport PDF creation
try {
//Getting JSON File as inputStream
InputStream is = new FileInputStream(sFileName);
//Creating JSONDataSource Object
JsonDataSource jds = new JsonDataSource(is);
//Filling ReportFile with JSON Data from file
jasperPrint = JasperFillManager.fillReport(reportStream, params, jds); //<<-- Is this where the problem is?
//Creating the PDF file for web loading.
JasperExportManager.exportReportToPdfFile(jasperPrint, sFilePDF); // <<-- or this one?
//Closing the JSON File inputStream
jds.close();
is.close();
//Closing the JasperReport File Stream
reportStream.close();
//Passing the filename to the browser for jquery handling.
response.getWriter().write(sFilePDF.replace(pReader.getPropValue(pReader.GETREPORTMPLTOUT),
request.getContextPath() + pReader.getPropValue(pReader.GETREPORTMPLTDIR)));
} catch (JRException e) {
log.setLogInfo(sUser, sSID, "Report [createReport] create report error [" + sFilePDF + "]["
+ sReportType + "][" + sDateFrom + " - " + sDateTo + "] ["
+ e.getLocalizedMessage() + "]");
} catch (FileNotFoundException ex) {
log.setLogFatal(sUser, sSID, ex.getMessage());
} catch (Exception e) {
log.setLogFatal(sUser, sSID, e.getMessage());
}
logMe.setLogInfo(sUser, sSID, "exiting createreport");
return null;
}
感谢任何人对此事的帮助。
下面是json源和jrxml文件。
文件名:c7070payroll.json
内容:
{"rows":[{"acctno":"3008000017","approved":false,"approvedby":"Test","batchcount":1,"branchid":"ff39540a6ded24c3feba8501a42fc34b","cashcard":false,"class":"com.upload.PayHeader","clientid":"3bedcbe428fc959e87e92062358bdaf3","compname":"test user 123","date_approved":1344441600000,"date_credit":1344488158000,"date_processed":null,"date_uploaded":1344488158000,"id":"9465306278db2ac8386c745fcd5eae6f","istpd":true,"payroll_filename":"AA10809001.java","processed":false,"processed_by":null,"status":2,"status_desc":"Approved, With Warnings","total_amount":49993040.71,"total_records":11,"uploaded_by":"Test"},{"acctno":"6018539400951087","approved":true,"approvedby":"Test","batchcount":2,"branchid":"ff39540a6ded24c3feba8501a42fc34b","cashcard":false,"class":"com.upload.PayHeader","clientid":"862bb9ea069ea12c9bff2051871a8102","compname":"Test User 456","date_approved":1344488172000,"date_credit":1344488172000,"date_processed":null,"date_uploaded":1344488172000,"id":"dac748c0b1101d40f0916039e92253d3","istpd":true,"payroll_filename":"GOFISH.java","processed":false,"processed_by":null,"status":2,"status_desc":"REJECT, Invalid syntax","total_amount":250000.0,"total_records":10,"uploaded_by":"Test"}]}
文件名:PQ4.jrxml
xml内容:
`<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="PFBA_Q4" pageWidth="1008" pageHeight="612" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="968" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true" uuid="cb26c490-b5d4-4f6a-b2a6-5fa0cae6269a">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<parameter name="branchid" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="datefrom" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="dateto" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<parameter name="reportby" class="java.lang.String">
<defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString language="json">
<![CDATA[rows]]>
</queryString>
<field name="payroll_filename" class="java.lang.String">
<fieldDescription><![CDATA[payroll_filename]]></fieldDescription>
</field>
<field name="date_uploaded" class="java.lang.String">
<fieldDescription><![CDATA[date_uploaded]]></fieldDescription>
</field>
<field name="uploaded_by" class="java.lang.String">
<fieldDescription><![CDATA[date_uploaded]]></fieldDescription>
</field>
<field name="total_records" class="java.lang.String">
<fieldDescription><![CDATA[total_records]]></fieldDescription>
</field>
<field name="total_amount" class="java.lang.String">
<fieldDescription><![CDATA[total_amount]]></fieldDescription>
</field>
<field name="acctno" class="java.lang.String">
<fieldDescription><![CDATA[acctno]]></fieldDescription>
</field>
<field name="compname" class="java.lang.String">
<fieldDescription><![CDATA[compname]]></fieldDescription>
</field>
<field name="status_desc" class="java.lang.String">
<fieldDescription><![CDATA[status_desc]]></fieldDescription>
</field>
<field name="date_credit" class="java.lang.String">
<fieldDescription><![CDATA[date_credit]]></fieldDescription>
</field>
<field name="branchid" class="java.lang.String">
<fieldDescription><![CDATA[branchid]]></fieldDescription>
</field>
<sortField name="compname"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="37" splitType="Stretch"/>
</title>
<pageHeader>
<band height="55" splitType="Stretch">
<staticText>
<reportElement uuid="8ccadef7-6c06-446f-b0d0-2018c9e7f483" x="0" y="0" width="968" height="17"/>
<textElement textAlignment="Center"/>
<text><![CDATA[Payroll Files]]></text>
</staticText>
<textField>
<reportElement uuid="ff174d4e-2373-4c37-99ca-ccf09a0a9d0a" x="0" y="17" width="968" height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA["Date Covered: uploaded from " + $P{datefrom} + " to " + $P{dateto}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement uuid="86b5b2f5-288d-4348-8972-ad0e04748cbe" x="0" y="35" width="209" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Branch : " + $F{branchid}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="34f96cc7-3432-46c5-b7fb-3bbed5313e5d" x="767" y="17" width="190" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Username : " + $P{reportby}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="34a055ac-5d93-4bd4-a751-69558a68fb92" x="0" y="35" width="968" height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA["Credit Date : " + $F{date_credit}]]></textFieldExpression>
</textField>
<textField>
<reportElement uuid="f3f837e7-e18a-4f5a-aa5f-a55a5537f669" x="767" y="0" width="190" height="20"/>
<textElement/>
<textFieldExpression><![CDATA["Run Time: " + new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new Date())]]></textFieldExpression>
</textField>
</band>
</pageHeader>
<columnHeader>
<band height="20" splitType="Stretch">
<staticText>
<reportElement uuid="d915b454-6e34-41a3-92f4-c93a4d03e5b7" x="0" y="0" width="133" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[File Name]]></text>
</staticText>
<staticText>
<reportElement uuid="5b0d3978-a6c4-48ff-8a1c-614a8d53f4f2" x="133" y="0" width="210" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Company Name]]></text>
</staticText>
<staticText>
<reportElement uuid="a8a922cf-cba0-4a4e-a2f9-ed8f5af32504" x="343" y="0" width="92" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Funding Account]]></text>
</staticText>
<staticText>
<reportElement uuid="6115ab0f-f03e-4a69-a01b-818435449557" x="435" y="0" width="108" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Total Records]]></text>
</staticText>
<staticText>
<reportElement uuid="185caa20-f79e-4c9e-867a-b6bf03efaa0d" x="543" y="0" width="127" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Total Amount]]></text>
</staticText>
<staticText>
<reportElement uuid="0958726b-82a4-4b76-9cb3-b356c2557627" x="670" y="0" width="96" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Uploaded By]]></text>
</staticText>
<staticText>
<reportElement uuid="a1e2a408-5e0b-4500-9cb3-7043cdd8e173" x="863" y="0" width="92" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Status]]></text>
</staticText>
<staticText>
<reportElement uuid="fc089d99-48d1-4f0a-98c8-e8f5f49bf8af" x="766" y="0" width="97" height="20"/>
<box topPadding="1" leftPadding="1" bottomPadding="1" rightPadding="1">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Date Uploaded]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="20" splitType="Stretch">
<textField isBlankWhenNull="false">
<reportElement uuid="f970775b-c503-4ab1-bb29-c1662a4992aa" x="0" y="0" width="133" height="20"/>
<box leftPadding="2" rightPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{payroll_filename}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="4788efc7-f02c-4403-acbf-25ec62284ba0" x="133" y="0" width="210" height="20"/>
<box leftPadding="2" rightPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{compname}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="a7854a19-4f54-46e3-9d6f-3d03ce0fbf9c" x="343" y="0" width="92" height="20"/>
<box leftPadding="2" rightPadding="10">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{acctno}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="3291695f-b819-4f73-a50c-afada4d610a6" x="670" y="0" width="96" height="20"/>
<box leftPadding="5" rightPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{uploaded_by}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="ea7f214d-e1f4-4a28-880b-6dc344c325c8" x="863" y="0" width="92" height="20"/>
<box leftPadding="2" rightPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{status_desc}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="false">
<reportElement uuid="1236a160-8ddf-4087-80fb-8305f54eb52e" x="766" y="0" width="97" height="20"/>
<box leftPadding="5" rightPadding="2">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Justified" verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{date_uploaded}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="ab50b2bb-17f4-4c28-bbfb-5c31a00de251" x="435" y="0" width="108" height="20"/>
<box leftPadding="5" rightPadding="5">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{total_records}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="false">
<reportElement uuid="7b6afcf5-de34-45bb-84ab-3844d786f97b" x="543" y="0" width="127" height="20"/>
<box leftPadding="5" rightPadding="5">
<pen lineWidth="0.25"/>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="Arial" size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{total_amount}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
`