views:

2032

answers:

2

Hello!
I'm trying to get myself used to jasperforge ireport before using it in a real project next week and i seem to be stacked somewhere already .i'm using ireport 3.7.0 on windows xp platform + java 1.6

It sound easy to get a field color changed based on what it contains or calculate a sum of number in a field based on conditions but in practice it's taking me too much time to accomplish. I have a query say :

SELECT COUNT(gender) AS total_by_gender, gender ,account_status  FROM user_account ua, user_profile up WHERE ua.user_profile_id=up.user_profile_id GROUP BY gender,account_status

it gives me something like this:

    | total_by_gender | gender | account_status |  
    | 160             |Female  | ENABLED        |  
    | 26              |Female  | UNCONFERIMED   |  
    | 100             |Male    | ENABLED        |
    | 10              |Male    | UNCONFIRMED    |    

Now i want the ENABLED Text to Look say green and UNCONFIRMED say red.For that i added a text field with this expression

$F{account_status}.equals( new String("ENABLED") ) ? "<style forecolor='#ff0000'>" + $F{account_status}.toString() + "</style>" :"<style forecolor='#999999'>" + $F{account_status}.toString() + "</style>"    
//i've tried this too
$F{account_status}.contentEquals( new String("ENABLED") )  ? 
//and even  
($F{account_status}.toString =="ENABLED"  ) ?

well for each of them it gives me something like the same text like <style> (i think it's printing all the condition expression) instead of colored text unconfirmed or enabled.

My second problem is that i want to do the total of all unconfirmed and all enabled. i can do normal sum expression but with condition i don't have any idea. Can anyone shed some light? thanks for reading

A: 

Two issues here. 1. Your condition statement doesn't work. Try $F{account_status}.equals("ENABLED"). It will work. 2. You want to colour the text based on some condition. Check if iReport supports conditional colouring on textfield. If it does, try not to pollute the content with colour information (). Colour information has to be on the textfield and not the content of textfield. Please give complete textfield definition that you are using.

I'll try this myself tomorrow.

Nayn
ok i got the condition working for other purpose yesterday dropping the coroloring of the textfield.During my research on google i only see what i've posted but i've also noticed that it's for older versions.Getting this kind of information for ireport 3.7.0 or simply version 3 seems to be rare.thanks for your reply
black sensei
so did you resolve the coloring issue or the conditional sum? or both?
medopal
not at all man.Still on it!no response
black sensei
+1  A: 

Try this. Define a style as below.

     <style name="myStyle" isDefault="false" mode="Transparent">
          <conditionalStyle>
              <conditionExpression><![CDATA['YOUR CONDITION']]></conditionExpression>
              <style isDefault="false" style="myStyle" backcolor="#E6DAC3"/>
          </conditionalStyle>
     </style>

And use it in your textFieldExpression

     <reportElement style="myStyle" x="1" y="0" width="100" height="15"/>
Nayn