To use conditionals in a Jasper template, you can use any field. If you want to use a boolean, you should add "_boolean" to the end of the field name. That is, "<metadata_name>_boolean".
To create the condition you should use the following structure:
(condition) ? "value_if_true" : "value_if_false"
For example, a very basic Jasper template with a condition and a boolean could be as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="axa-soat" pageWidth="612" pageHeight="792" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b61e5225-424a-4108-900b-a1114c933e56">
<parameter name="<metadata_name>_boolean" class="java.lang.Boolean"/>
<detail>
<band height="128">
<textField>
<reportElement x="9" y="90" width="265" height="35" uuid="b27d51ca-bc73-4708-af4a-d9060e3410d1"/>
<textElement textAlignment="Left" verticalAlignment="Middle">
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[($P{<metadata_name>_boolean}) ? "verdadero" : "falso"]]></textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>
In this example, if the field is true, "true" will be displayed in the template, and if false, "false" will be displayed. For conditions, you can also use the ".equals()" operator. For example:
($P{<metadata_name>}.equals("test")) ? "test_true" : "test_false"
Comments
0 comments
Please sign in to leave a comment.