Jump to content
We've recently updated our Privacy Statement, available here ×
  • How to use Java 5 expressions in a report?


    djohnson53
    • Version: v5.1, v5.0, v4.8, v4.7, v4.6, v4.5 Product: JasperReports® Library

    Java 5 enhancements such as autoboxing/unboxing can be leveraged to make report expressions more concise and simpler to understand.

    For instance, the following JRXML fragment

    <parameter name="A" class="java.lang.Integer">  <defaultValueExpression>    new Integer(3)  </defaultValueExpression></parameter>...<textField>  <reportElement x="280" y="150" width="200" height="35">    <printWhenExpression>      Boolean.valueOf($P{A} != null)    </printWhenExpression>  </reportElement>  <textFieldExpression class="java.lang.Integer">    new Integer($P{A}.intValue() * 2)  </textFieldExpression></textField>[/code]

    would look like this when using autoboxing/unboxing:

    <parameter name="A" class="java.lang.Integer">  <defaultValueExpression>3</defaultValueExpression></parameter>...<textField>  <reportElement x="280" y="150" width="200" height="35">    <printWhenExpression>      $P{A} != null    </printWhenExpression>  </reportElement>  <textFieldExpression class="java.lang.Integer">    $P{A} * 2  </textFieldExpression></textField>[/code]

    To use Java 5 syntax in the report expressions, you need to make sure that the report compiler compiles Java 5 code.

    JDK-based report compilers automatically compile Java 5 code when using JDK 5 or newer.

    The JDT-based report compiler, which is recommended when compiling reports at runtime (see this FAQ), needs to be configured to compile Java 5 code. This can be done by including the following properties in the jasperreports.properties file (which needs to be placed on the application's classpath):

    org.eclipse.jdt.core.compiler.source=1.5org.eclipse.jdt.core.compiler.compliance=1.5org.eclipse.jdt.core.compiler.codegen.TargetPlatform=1.5[/code]

    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...