Jump to content

conditional statement to change fore color


askme

Recommended Posts

Hi all,

            I am using a conditional statement to change the font color in jrxml. The condition is if the value is greater than 0 then one color else another color.

Please find the statement that i used in the jrxml file in the code section below.

The field is of type string

    <field name="total" class="java.lang.String"/>

 

I get the following error when i try to generate the report

 

 

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The method doubleValue() is undefined for the type String
                value = (java.lang.String)(((java.lang.String)field_total.getValue()).doubleValue() >0.0 ? //$JR_EXPR_ID=16$
                                                                                            <--------->
2. The method doubleValue() is undefined for the type String
                value = (java.lang.String)(((java.lang.String)field_total.getOldValue()).doubleValue() >0.0 ? //$JR_EXPR_ID=16$
                                                                                               <--------->
3. The method doubleValue() is undefined for the type String
                value = (java.lang.String)(((java.lang.String)field_total.getValue()).doubleValue() >0.0 ? //$JR_EXPR_ID=16$
                                                                                            <--------->

 

Thanks

Code:
<textField >				<reportElement x="607" y="0" width="70" height="20"/>				<textElement textAlignment="Center"/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{total}.doubleValue() >0.0 ?    ("<style forecolor='#ff0000'>"+ $F{total}.toString()+"</style>"):    ("<style forecolor='#0000ff'>"+ $F{total}.toString()+"</style>")]]></textFieldExpression>			</textField>			
Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...