jasper-reports

Getting "Error evaluating expression for source text" for parameter declared as String with numeric value


I'm getting an error with unclear root cause

net.sf.jasperreports.engine.fill.JRExpressionEvalException: 
Error evaluating expression for source text: $P{account} != null

when trying to render a JasperReports report with the below part:

<parameter name="account" class="java.lang.String">
    <defaultValueExpression><![CDATA["11111"]]></defaultValueExpression>
</parameter>
    ....
<textField textAdjust="StretchHeight" isBlankWhenNull="true">
     <reportElement x="75" y="140" width="320" height="20">
         <printWhenExpression><![CDATA[$P{account} != null]]></printWhenExpression>
      </reportElement>
      <textFieldExpression><![CDATA[$P{account}]]></textFieldExpression>
</textField>

The Java code executing the rendering to the InputStream is:

Long abAccount = someLong();
parameters.put("account", abAccount);
parameters.put("url", "urlhardcodedthere");

List<Param> list = new ArrayList<>();

JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(list);
JasperRunManager.runReportToPdf(report, parameters, dataSource);

What is wrong and what the root cause of the error?


Solution

  • The reason was a type mismatch, Long value was passed as a parameter, while the JRXML required the String parameter with this name.

    parameters.put("account", abAccount+""); //makes a String value to be passed
    

    solved the problem