jasper报告带有空值的pdf

时间:2017-12-19 12:27:05

标签: java jasper-reports

我使用以下代码

创建一个jasper报告
JasperPrint print = null;
    Map<String, Object> datosReporte = new HashMap<String, Object>();

    JasperReport reporteJasper = crearReporteJasper();
    String rutaPDF = "C:\\AAPG\\algo.pdf";

    try {

        for (int i =0; i< lista.size(); i++) {

            Fin700PDFVO r = (Fin700PDFVO)lista.get(i);

                    datosReporte.put("PROVEEDOR", r.getProveedor());
                    datosReporte.put("RUT", Integer.toString(r.getRut()));
                    datosReporte.put("TIPO", r.getTipo());
                    datosReporte.put("CANTREGISTROS", Integer.toString(r.getCantRegistros()));
                    datosReporte.put("SUMTOTUF", Integer.toString(r.getSumTotUF()));
                    datosReporte.put("SUMTOTPESOS", Integer.toString(r.getSumTotPesos()));


        }
            print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JREmptyDataSource());
            JasperExportManager.exportReportToPdfFile(print, rutaPDF);

private JasperReport crearReporteJasper() {
    JasperReport report = null;
    String sourceFileName = "ReporteFin700";
    InputStream is = null;

    try {
        is = this.getClass().getResourceAsStream("/resources/" + sourceFileName + ".jrxml");
        report = JasperCompileManager.compileReport(is);
    } catch (Exception e) {
        logger.error("Error al compilar plantilla: " + sourceFileName, e);
        throw new ServiceException("Error al compilar plantilla: " + sourceFileName);
    }
    return report;

但是当试图运行这段代码时,我得到一个带有de列标题的pdf,值为null。

1 个答案:

答案 0 :(得分:0)

我解决了它改变了JREmptyDataSource,就像Alex K提到的那样,改变了这个:

print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JREmptyDataSource());

这个

print = JasperFillManager.fillReport(reporteJasper, datosReporte, new JRMapArrayDataSource(new Object[] { datosReporte }));