我创建了一个加载JR报告的程序。我在报告上放置了一个参数,这样每当报告加载时,它都会要求一个值。当我在我的java程序上传递一个参数时它工作正常
Map parameters = new HashMap();
parameters.put("VoucherNo", oclsJVHeader.getJournalVoucherNo());
...
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn);
但是当我尝试在没有参数的情况下加载它时,
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
它说“文件没有页面”。我在想,因为每当我的代码没有传递参数时我都会使用提示,所以当我加载它时它会询问提示。
<parameter name="VoucherNo" class="java.lang.String" isForPrompting="true">
所以我的问题是,每当我不传递参数时,如何让报告提示值?我需要更改我的java代码吗?
顺便说一下,这是我加载报告的代码:
FileInputStream fs = new FileInputStream(reportPath+reportFile);
JasperDesign jasperDesign = JRXmlLoader.load(fs);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, conn); //could be null or parameters
JFrame jframe = new JFrame("Journal Voucher");
jframe.getContentPane().add(new JRViewer(jasperPrint));
jframe.pack();
jframe.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
jframe.setVisible(true);
我正在为我的项目使用 iReport 和 NetBeans 。
答案 0 :(得分:4)
AFAIK,isForPrompting
参数仅供iReport和JasperServer使用(并且可由任何其他生成报告的通用应用程序使用)。
无论如何,JasperReport应该如何知道它应该如何询问参数值?如果您的应用程序是webapp?还是一个命令行应用程序? Jasper Reports生成报告。您应该提供必要的GUI。