I have a frame, I am using that frame to display the gender field. I have added two textfields
in that frame, one to display gender label and other to display gender field value. When gender fields are empty Jasper is rendering empty line, I want to remove this empty line.
<frame>
<reportElement key="govi" positionType="Float" stretchType="RelativeToTallestObject" x="124" y="154" width="403" height="17" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="ff3e33f8-cc51-45c3-a3ed-513832d6e180"/>
<staticText>
<reportElement x="0" y="0" width="141" height="15" uuid="9700c67a-9385-4dd5-8626-23a8261bc2b5"/>
<text><![CDATA[Person with Disability ]]></text>
</staticText>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="140" y="0" width="245" height="15" isPrintWhenDetailOverflows="true" uuid="69f221ef-ae6b-40c6-98fd-dec7b91a6269"/>
<textElement textAlignment="Justified">
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[($F{is_pd} ? "Yes" : "No")]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement key="genderField" positionType="Float" stretchType="RelativeToTallestObject" x="124" y="114" width="393" height="15" isPrintWhenDetailOverflows="true" uuid="464b5c89-e158-4783-8f21-7b05f567e55e"/>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="104" height="15" isRemoveLineWhenBlank="true" uuid="0a77a60f-19ef-4634-84df-7a7f7f94ed14"/>
<textElement>
<font size="10" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[($F{country_id} != 1 ? "Gender" : null )]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="140" y="0" width="231" height="15" isRemoveLineWhenBlank="true" uuid="884fe0ef-654c-46e0-8399-d9fed8722a76"/>
<textElement>
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[($F{country_id} != 1 ? $F{gender} : null )]]></textFieldExpression>
</textField>
</frame>
<frame>
<reportElement key="govi" positionType="Float" stretchType="RelativeToTallestObject" x="124" y="134" width="402" height="17" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" uuid="a4cbd87c-ea2d-4952-8bc4-0a7e6e655e28"/>
<staticText>
<reportElement x="0" y="0" width="69" height="15" uuid="e289c5be-91c4-4a74-b3d6-57c800401d0a"/>
<text><![CDATA[Category]]></text>
</staticText>
<textField isStretchWithOverflow="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="140" y="0" width="231" height="15" isRemoveLineWhenBlank="true" uuid="c01465ce-fb3d-47ba-9c29-bdfd7be7424f"/>
<textElement>
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[($F{category_id} == 1 ? "GEN" : ($F{category_id} == 2 ? "OBC" : ($F{category_id}==3 ? "SC" : "ST")))]]></textFieldExpression>
</textField>
</frame>
I have applied isRemoveLineWhenBlank="true"
on frame as well as two textfield,isBlankWhenNull="true"
is applied on both the textfields still no success. Am I missing something?
It is simple to fix your issue - you should set
isRemoveLineWhenBlank="true"
for the first textField (with($F{country_id} != 1 ? "Gender" : null
epxression). In this case everything will be fine.I modified your template for check as
and it works like a charm:
You get the result above for example using combinations of parameters like:
In case using this values:
the reslut will be:
You can also simplify this fragment as at this example:
In this sample the isRemoveLineWhenBlank and printWhenExpression used only for frame element.
It is works the same as this example:
The result will be the same, for example in case
country_id == 1
:UPDATE
You forgot to set
isRemoveLineWhenBlank="true"
for frame with gender in your new snippet. After making this fix your new sample also works well in iReport 5.6.0. I replaced fields with parameters for testing purpose and change the order of frames to hide the frame with gender.The jrxml file:
The design in iReport looks like:
I set parameters like this:
The generated report for this parameters looks like:
In case using this set
the result will be: