抛出Jasper报告中的例外情况

时间:2016-01-04 07:28:41

标签: java jasper-reports

我希望停止用户从Jasper下载大量报告。 REPORT_MAX_COUNT执行此任务,但用户不知道其生成的部分数据。

当REPORT_COUNT大于REPORT_MAX_COUNT时,我想从Jasper抛出异常。因此用户可以相应地优化搜索过滤器是否可以从Jasper中抛出异常?

1 个答案:

答案 0 :(得分:1)

我会避免从报告中抛出异常,因为否则你可以处理它。

相反,我会使用这些选项:

  1. 我想在生成报告后控制是否显示(看起来像你的情况),检查报告后的REPORT_COUNT >= REPORT_MAX_COUNT是否已填写。
  2. 示例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...");
        }
    }
    

    如果你喜欢System.out;

    ,而不是throw new Exception("OOPS")做你的东西
    1. 如果REPORT_COUNT >= REPORT_MAX_COUNT
    2. ,则在报告中显示警告文字

      示例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>
      
      1. 同时执行..,在界面中显示警告,但如果他愿意,让用户可以下载带有警告文字的生成报告....
相关问题