[英]Throw Exceptions from Jasper Reports
我希望停止用户从Jasper下载大量报告。 REPORT_MAX_COUNT可以完成这项工作,但是用户不知道它生成了部分数据。
当REPORT_COUNT大于REPORT_MAX_COUNT时,我想从Jasper抛出异常。 因此,用户可以相应地优化搜索过滤器。 是否可以从Jasper引发异常?
我将避免从报告中引发异常,因为您可以以其他方式处理它。
相反,我将使用以下选项:
REPORT_COUNT >= REPORT_MAX_COUNT
。 示例Java代码:
JasperReport report = JasperCompileManager.compileReport("yourReport.jrxml");
JRBaseFiller filler = JRFiller.createFiller(DefaultJasperReportsContext.getInstance(),report); //we need the filler to get the variable value
JasperPrint print = filler.fill(map, connection);
Object rc = filler.getVariableValue("REPORT_COUNT");
Object maxRc = filler.getParameterValue("REPORT_MAX_COUNT");
if (rc instanceof Number && maxRc instanceof Number){
if (((Number)rc).intValue()>=((Number)maxRc).intValue()){
System.out.println("REPORT_MAX_COUNT HIT!!, doing something else...");
}
}
如果您想throw new Exception("OOPS")
,请代替System.out
操作;
REPORT_COUNT >= REPORT_MAX_COUNT
在报告内显示警告文本 示例jrxml代码:
<summary>
<band height="20">
<textField evaluationTime="Report">
<reportElement x="0" y="0" width="200" height="20" isRemoveLineWhenBlank="true" forecolor="#FF0033" uuid="82b89600-1787-4a86-809e-adc5babdd6b6">
<printWhenExpression><![CDATA[$V{REPORT_COUNT}.intValue()>=$P{REPORT_MAX_COUNT}.intValue()]]></printWhenExpression>
</reportElement>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["REPORT_MAX_COUNT HIT"]]></textFieldExpression>
</textField>
</band>
</summary>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.