2012-04-15 22 views
0

我是JasperReports中的新成员。 当某些变量设置为'3'时,我想获得斜体文本。JasperReport - TextElement中的条件

这里是我的代码:

<textElement> 

    <font size="9" pdfFontName="Helvetica" pdfEncoding="Cp1250" isPdfEmbedded="true" 
    isItalic=<![CDATA[$F{variable}==3 ? "true" : "false"]]> /> 

</textElement> 

我在做什么错?

我也试过做有条件的风格,但无论我把我recive错误。

回答

0

在表达式的帮助下,您无法使用属性isItalic(以及其他许多属性)的设置值。

在你的情况下,你应该使用conditional style

样品:

<?xml version="1.0" encoding="UTF-8"?> 
<jasperReport ..> 
    <style name="customStyle"> 
     <conditionalStyle> 
      <conditionExpression><![CDATA[$F{variable} == 3]]></conditionExpression> 
      <style isItalic="true"/> 
     </conditionalStyle> 
    </style> 
    ... 
    <detail> 
     <band height="20" splitType="Stretch"> 
      <textField> 
       <reportElement style="customStyle" mode="Opaque" x="100" y="0" width="100" height="20"/> 
       <textElement/> 
       <textFieldExpression><![CDATA[$F{value}]]></textFieldExpression> 
      </textField> 
     </band> 
    </detail> 
</jasperReport>