0

I would like to make a dynamic change font property based on variable condition.

I have already searched on the stackoverflow's questions but I didn't find anything for this detail.

Below my snippet code:

    <textField>
      <reportElement style="DetailsPrice" x="370" y="5" width="56" height="15" uuid="2f0dc291-6a8b-48d3-b7d1-fe931b88e859">
        <property name="com.jaspersoft.studio.unit.y" value="px"/>
        <property name="com.jaspersoft.studio.unit.x" value="mm"/>
        <property name="com.jaspersoft.studio.unit.height" value="mm"/>
          <printWhenExpression>
             <![CDATA[$F{product_unformatted_discount_amount} != null && $F{product_unformatted_discount_amount} != 0]]>
          </printWhenExpression>
      </reportElement>
      <textElement textAlignment="Left" verticalAlignment="Middle">
         <font isBold="true" isStrikeThrough="true"/>
      </textElement>
        <textFieldExpression><![CDATA["+" + $F{product_price_formatted_amount}]]></textFieldExpression>
    </textField>

How can I change isStrikeThrough property value depending on $F{product_unformatted_discount_amount} value ? In a nutshell I would like to apply condition in line in the font tag.

Thanks

Alex K
  • 22,315
  • 19
  • 108
  • 236
Stefano
  • 1,439
  • 4
  • 23
  • 38

1 Answers1

0

I resolved via markup tag with styled value.

Markup documentation

code snippet:

<textElement textAlignment="Left" verticalAlignment="Middle" markup="styled"/>
<textFieldExpression>
      <![CDATA[$F{product_unformatted_discount_amount} != null && $F{product_unformatted_discount_amount} != 0 ? "<style isStrikeThrough='true' isBold='true'> +" + $F{product_price_formatted_amount} + "</style>" : "<style isStrikeThrough='false' isBold='true'> +" + $F{product_price_formatted_amount} + "</style>"]]>
</textFieldExpression>

I put the markup tag with styled value into textElement tag, while isStrikeThrough tag in the textFieldExpression tag implementing if inline

markup=styled This markup is capable to format the text using a set of HTML-like tags and it is pretty popular in the Java environments. It allows to set a specific font for chunks of text, color, background, style and so on. It's often good enough to format the text programmatically.

Stefano
  • 1,439
  • 4
  • 23
  • 38