Jasper reports compile error for SUM function with

2019-09-05 14:49发布

I am using jasper reports to generate reports from my spring mvc application.

It works fine as long as I do not use any math functions in jasper report. For example the SUM function in jasper reports gives me a compile time error on my application -

1. The method SUM(int) is undefined for the type ContentUsageStatisticsReport_1426086372880_332015
                value = SUM(((java.math.BigDecimal)field_cnt.getValue()).intValue()); //$JR_EXPR_ID=15$

Here is the field from jasper reports.

<textField>
            <reportElement x="210" y="1" width="130" height="20" uuid="45fbed39-f63a-41ff-8ff1-88821aeefcd1"/>
            <textFieldExpression><![CDATA[SUM($F{cnt}.intValue())]]></textFieldExpression>
</textField>

Does this mean that I cannot use Jasper functions in the report and the calculations must be done on server? If so, then how do I calculate subtotals for each page of the report?.

1条回答
时光不老,我们不散
2楼-- · 2019-09-05 15:12

I solved this problem by creating a variable that calculates the SUM of the required field -

<variable name="subtotal_of_cnt" class="java.math.BigDecimal" resetType="Group" resetGroup="isALUEmployee" calculation="Sum">
        <variableExpression><![CDATA[$F{cnt}]]></variableExpression>
</variable>

and used it -

<textField>
                    <reportElement x="210" y="1" width="130" height="20" uuid="45fbed39-f63a-41ff-8ff1-88821aeefcd1"/>
                    <textFieldExpression><![CDATA[$V{subtotal_of_cnt}]]></textFieldExpression>
</textField>

This works because variables are evaluated after the report is compiled and populated.

查看更多
登录 后发表回答